[29611] in Perl-Users-Digest
Perl-Users Digest, Issue: 855 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 16 14:09:46 2007
Date: Sun, 16 Sep 2007 11:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 16 Sep 2007 Volume: 11 Number: 855
Today's topics:
Re: `command 2>&1 > file` without the shell? <ben@morrow.me.uk>
Re: form script question <john@.>
how to get # of occurances of a character in a given st <vijay@iavian.com>
Re: how to get # of occurances of a character in a give <ben@morrow.me.uk>
Re: how to get # of occurances of a character in a give <dummy@example.com>
Re: how to get # of occurances of a character in a give <mgjv@tradingpost.com.au>
Re: how to remove parentheses from a line in a file - n <pauls@nospam.off>
Re: how to remove parentheses from a line in a file - n <see.sig@rochester.rr.com>
Installing XS Modules on Windows -- Like Pulling Teeth FeelLikeANut@gmail.com
Re: Installing XS Modules on Windows -- Like Pulling Te <thepoet_nospam@arcor.de>
Re: Installing XS Modules on Windows -- Like Pulling Te FeelLikeANut@gmail.com
new CPAN modules on Sun Sep 16 2007 (Randal Schwartz)
Newbie question: load data to array <masferfc@gmail.com>
Re: Newbie question: load data to array charley@pulsenet.com
Problem with my perl script - old records getting over <vivekm1234@cyberspace.org>
Re: Problem with my perl script - old records getting o <vivekm1234@cyberspace.org>
Re: Problem with my perl script - old records getting o <vivekm1234@cyberspace.org>
Re: Problem with my perl script - old records getting o <vivekm1234@cyberspace.org>
Re: Problem with my perl script - old records getting o <dummy@example.com>
Re: Question on input password on ssh prompt <ben@morrow.me.uk>
sqDILJAWOPFIAEGOPIWEGOPIWOP <Fleischmann.chchch@googlemail.com>
Re: strange behaviour with 'use open IN => ":byte" <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Sep 2007 11:23:41 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: `command 2>&1 > file` without the shell?
Message-Id: <dqcvr4-281.ln1@osiris.mauzo.dyndns.org>
Quoth kj <socyl@987jk.com.invalid>:
>
> If I wanted to execute an external (unix) command X such that X's
> normal output went to some file, but any error messages from X were
> saved to an array, I could, for example, do this:
>
> my @err = `X 2>&1 > some_file`;
>
> How could I achieve the same results without using the shell?
Use IPC::Run.
Ben
------------------------------
Date: Sun, 16 Sep 2007 02:00:13 -0400
From: "mnwebguy" <john@.>
Subject: Re: form script question
Message-Id: <7638e2742e94ce2e1fc4d697c8bfe1b2@localhost.talkaboutprogramming.com>
create a hidden field in your form named "Subject" and give it a value,
then in forms.cgi - in the section
$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
replace:
-subject => "Feedback: from $form_meta->[2]",
with:
-subject => $form_field{Subject},
and it will do what you want, just be aware that the field name is case
sensitive and must match the form spelling including case
--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.perl.misc/
More information at http://www.talkaboutprogramming.com/faq.html
------------------------------
Date: Sun, 16 Sep 2007 11:22:57 -0000
From: "vijay@iavian.com" <vijay@iavian.com>
Subject: how to get # of occurances of a character in a given string
Message-Id: <1189941777.725242.278340@r29g2000hsg.googlegroups.com>
$str = "vijaya";
if my character is 'a' then it should get the number 2
------------------------------
Date: Sun, 16 Sep 2007 13:19:59 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to get # of occurances of a character in a given string
Message-Id: <fkjvr4-8i6.ln1@osiris.mauzo.dyndns.org>
Quoth "vijay@iavian.com" <vijay@iavian.com>:
> $str = "vijaya";
>
> if my character is 'a' then it should get the number 2
perldoc -q count
Ben
------------------------------
Date: Sun, 16 Sep 2007 12:20:52 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: how to get # of occurances of a character in a given string
Message-Id: <Ec9Hi.65571$vP5.29573@edtnps90>
vijay@iavian.com wrote:
> $str = "vijaya";
>
> if my character is 'a' then it should get the number 2
$ perl -le'
my $str = "vijaya";
my $count = $str =~ tr/a//;
print $count;
'
2
perldoc -q count
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Sun, 16 Sep 2007 22:15:14 +1000
From: Martien verbruggen <mgjv@tradingpost.com.au>
Subject: Re: how to get # of occurances of a character in a given string
Message-Id: <slrnfeq7ii.m61.mgjv@martien.heliotrope.home>
On Sun, 16 Sep 2007 11:22:57 -0000,
vijay@iavian.com <vijay@iavian.com> wrote:
> $str = "vijaya";
>
> if my character is 'a' then it should get the number 2
And the actual question is:
> how to get # of occurances of a character in a given string
which I has to get from the subject line.
One possible answer can be found in the perlop documentation, under the
tr/// operator.
my $count = $str =~ tr/a//;
Martien
--
|
Martien Verbruggen | We are born naked, wet and hungry. Then
| things get worse.
|
------------------------------
Date: Sun, 16 Sep 2007 08:41:58 -0700
From: pauls <pauls@nospam.off>
Subject: Re: how to remove parentheses from a line in a file - need help!
Message-Id: <q-qdnW7166GF0nDbnZ2dnUVZ_uTinZ2d@seanet.com>
pauls wrote:
> Hi,
> I have a line of text like this:
>
> m1 (d g s b) en (w=wdnfing l=l as=1e-20 ad=1e-20 ps=1e-20 pd=1e-20)
>
>
> I am reading-in the file in using $_ and I tried to do the following
> (without success):
>
> s/)//g;
> s/)//g;
>
> I also tried:
>
> s')''g;
> s'(''g;
>
> Why do both of these attempts fail? And, could someone show me the right
> way (or one possible way) to get the job done?!
>
> Thanks
>
> P.
Thanks guys, that helped a lot!
What does it mean to "escape" from regxpr ?
This kind of thing comes-up all the time for me as it seems I am
frequently trying to massage a text file to remove things Like
parentheses , brackets and also quotes and dollar signs $.
Thanks!
Paul
------------------------------
Date: Sun, 16 Sep 2007 12:48:12 -0400
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: how to remove parentheses from a line in a file - need help!
Message-Id: <46ed5dd4$0$18968$4c368faf@roadrunner.com>
pauls wrote:
...
> What does it mean to "escape" from regxpr ?
There are a number of characters that have special meaning in Perl
regular expressions, such as ^.*+?$()[]{}|\ . For the complete list, see:
perldoc perlre
In addition, a regular expression has a delimiter character, / by
default. If you desire these characters to have their literal meaning
rather than their special meaning, they must be "escaped". Usually this
is done with a \ preceding the character. For example:
/a.b/ will match the strings aab, abb, acb, adb, ...
/a\.b/ will match only the string a.b
Note that . is a regular expression metacharacter that has the property
of matching almost any single character when it appears in a regexp.
HTH.
...
> Paul
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sun, 16 Sep 2007 15:28:30 -0000
From: FeelLikeANut@gmail.com
Subject: Installing XS Modules on Windows -- Like Pulling Teeth
Message-Id: <1189956510.434956.235600@n39g2000hsh.googlegroups.com>
I'm running on Windows with ActivePerl, and I'm trying to install
XML::LibXML. It's not in the PPM repository, so that's out of the
question. I downloaded MinGW, so I have gcc, and I downloaded both
nmake and dmake. I ran perl -MCPAN -e shell, and then install PAJAS/
XML-LibXML-1.64.tar.gz. But I get the error 'C:\Perl\bin\perl.exe
Makefile.PL' returned status 512, won't make. I searched all around
for some kind of instructions or tutorial, but very few are for
Windows and even fewer say anything useful.
So what are all the steps I need to perform to be able to install any
CPAN module on a Windows machine?
------------------------------
Date: Sun, 16 Sep 2007 18:07:16 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Installing XS Modules on Windows -- Like Pulling Teeth
Message-Id: <46ed5440$0$4517$9b4e6d93@newsspool3.arcor-online.net>
FeelLikeANut@gmail.com schrieb:
> I'm running on Windows with ActivePerl, and I'm trying to install
> XML::LibXML. It's not in the PPM repository, so that's out of the
> question. I downloaded MinGW, so I have gcc, and I downloaded both
> nmake and dmake. I ran perl -MCPAN -e shell, and then install PAJAS/
> XML-LibXML-1.64.tar.gz. But I get the error 'C:\Perl\bin\perl.exe
> Makefile.PL' returned status 512, won't make. I searched all around
> for some kind of instructions or tutorial, but very few are for
> Windows and even fewer say anything useful.
>
> So what are all the steps I need to perform to be able to install any
> CPAN module on a Windows machine?
Building modules on Windows can be a bit non-trivial, especially
getting all the paths set correctly and the neccessary DLLs and
LIBs in the right places beforehand.
But for XML::LibXML there should be a binary package available
at the uwinnipeg repository, so you should be able to enter
ppm repo add http://theoryx5.uwinnipeg.ca/ppms uwinnipeg
ppm install XML::LibXML
on the command line and be done with it.
-Chris
------------------------------
Date: Sun, 16 Sep 2007 16:33:48 -0000
From: FeelLikeANut@gmail.com
Subject: Re: Installing XS Modules on Windows -- Like Pulling Teeth
Message-Id: <1189960428.479316.109550@w3g2000hsg.googlegroups.com>
On Sep 16, 12:07 pm, Christian Winter <thepoet_nos...@arcor.de> wrote:
> FeelLikeA...@gmail.com schrieb:
>
> > I'm running on Windows with ActivePerl, and I'm trying to install
> > XML::LibXML. It's not in the PPM repository, so that's out of the
> > question. I downloaded MinGW, so I have gcc, and I downloaded both
> > nmake and dmake. I ran perl -MCPAN -e shell, and then install PAJAS/
> > XML-LibXML-1.64.tar.gz. But I get the error 'C:\Perl\bin\perl.exe
> > Makefile.PL' returned status 512, won't make. I searched all around
> > for some kind of instructions or tutorial, but very few are for
> > Windows and even fewer say anything useful.
>
> > So what are all the steps I need to perform to be able to install any
> > CPAN module on a Windows machine?
>
> Building modules on Windows can be a bit non-trivial, especially
> getting all the paths set correctly and the neccessary DLLs and
> LIBs in the right places beforehand.
>
> But for XML::LibXML there should be a binary package available
> at the uwinnipeg repository, so you should be able to enter
>
> ppm repo addhttp://theoryx5.uwinnipeg.ca/ppmsuwinnipeg
> ppm install XML::LibXML
>
> on the command line and be done with it.
>
> -Chris
Oh, hotness! Thanks!
------------------------------
Date: Sun, 16 Sep 2007 04:42:15 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Sep 16 2007
Message-Id: <JoG2EF.HHA@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
BBS-Client-0.01
http://search.cpan.org/~cornelius/BBS-Client-0.01/
A Client Module For BBS
----
CGI-Multiscript-0.70
http://search.cpan.org/~morgothii/CGI-Multiscript-0.70/
Perl extension for Multiscript programming
----
CGI-Multiscript-0.71
http://search.cpan.org/~morgothii/CGI-Multiscript-0.71/
Perl extension for Multiscript programming
----
CPAN-1.91_55
http://search.cpan.org/~andk/CPAN-1.91_55/
query, download and build perl modules from CPAN sites
----
CSS-Moonfall-0.03
http://search.cpan.org/~sartak/CSS-Moonfall-0.03/
port of Lua's Moonfall for dynamic CSS generation
----
Catalyst-Component-ACCEPT_CONTEXT-0.04
http://search.cpan.org/~jrockway/Catalyst-Component-ACCEPT_CONTEXT-0.04/
Make the current Catalyst request context available in Models and Views.
----
Devel-Graph-0.11
http://search.cpan.org/~tels/Devel-Graph-0.11/
Turn Perl code into a graphical flowchart
----
Games-Tournament-Swiss-0.08
http://search.cpan.org/~drbean/Games-Tournament-Swiss-0.08/
FIDE Swiss Same-Rank Contestant Pairing
----
IO-Socket-Telnet-0.01
http://search.cpan.org/~sartak/IO-Socket-Telnet-0.01/
Transparent telnet negotiation for IO::Socket::INET
----
Kvasir-0.01
http://search.cpan.org/~claesjac/Kvasir-0.01/
General rule engine for analysis and stuff like that
----
Kvasir-0.02
http://search.cpan.org/~claesjac/Kvasir-0.02/
Generic rule based processing engine
----
Math-Random-MT-Auto-6.09
http://search.cpan.org/~jdhedden/Math-Random-MT-Auto-6.09/
Auto-seeded Mersenne Twister PRNGs
----
Module-Load-Conditional-0.18
http://search.cpan.org/~kane/Module-Load-Conditional-0.18/
Looking up module information / loading at runtime
----
Net-Social-Service-Vox-0.1
http://search.cpan.org/~simonw/Net-Social-Service-Vox-0.1/
a Vox plugin for Net::Social
----
Net-XMPP2-0.08
http://search.cpan.org/~elmex/Net-XMPP2-0.08/
An implementation of the XMPP Protocol
----
NetStumbler-Wap-0.09
http://search.cpan.org/~sscotto/NetStumbler-Wap-0.09/
Wap tools for NetStumbler
----
Parse-Eyapp-1.077
http://search.cpan.org/~casiano/Parse-Eyapp-1.077/
Extensions for Parse::Yapp
----
Perl-Critic-1.077
http://search.cpan.org/~elliotjs/Perl-Critic-1.077/
Critique Perl source code for best-practices
----
Scalar-Cycle-Manual-0.01
http://search.cpan.org/~nkh/Scalar-Cycle-Manual-0.01/
----
Sphinx-Search-0.05
http://search.cpan.org/~jjschutz/Sphinx-Search-0.05/
Sphinx search engine API Perl client
----
Statistics-Benford-0.04
http://search.cpan.org/~gray/Statistics-Benford-0.04/
calculate the deviation from Benford's Law
----
Term-VT102-ZeroBased-1.00
http://search.cpan.org/~sartak/Term-VT102-ZeroBased-1.00/
Term::VT102 but with zero-based indices
----
Time-UTC-0.004
http://search.cpan.org/~zefram/Time-UTC-0.004/
manipulation of UTC in terms of TAI
----
Tk-WidgetDump-1.34
http://search.cpan.org/~srezic/Tk-WidgetDump-1.34/
dump the widget hierarchie
----
WebService-YouTube-1.0.2
http://search.cpan.org/~yoshida/WebService-YouTube-1.0.2/
Perl interfece to YouTube
----
Wx-Perl-Packager-0.1
http://search.cpan.org/~mdootson/Wx-Perl-Packager-0.1/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 16 Sep 2007 15:20:30 -0000
From: philbo30 <masferfc@gmail.com>
Subject: Newbie question: load data to array
Message-Id: <1189956030.216623.198400@n39g2000hsh.googlegroups.com>
I have a file with data like this:
123
456
789
010
987
654
321
I want to load these values into an array called "$data". How do I
make this happen?
------------------------------
Date: Sun, 16 Sep 2007 09:02:58 -0700
From: charley@pulsenet.com
Subject: Re: Newbie question: load data to array
Message-Id: <1189958578.260166.264360@22g2000hsm.googlegroups.com>
On Sep 16, 11:20 am, philbo30 <masfe...@gmail.com> wrote:
> I have a file with data like this:
>
> 123
> 456
> 789
> 010
> 987
> 654
> 321
>
> I want to load these values into an array called "$data". How do I
> make this happen?
The manual explains this. See:
perlopentut
perlfunc (look for the function 'push')
Array names in perl are preceded with an '@' character, not '$'.
See: perlintro
Chris
------------------------------
Date: Sat, 15 Sep 2007 19:56:19 -0700
From: "Vivek.M" <vivekm1234@cyberspace.org>
Subject: Problem with my perl script - old records getting over written by new $completedData
Message-Id: <1189911379.690694.307390@w3g2000hsg.googlegroups.com>
Hi, Background: bttrack.py is a open src torrent tracker, that uses
the option --dfile fileName, to save state information in. The file is
bencoded and has parts of it's content in binary. The encoding specs
and file format are described here:
http://wiki.theory.org/BitTorrentSpecification#lists
I am trying to write my own Perl script to create my own "dfile".
Data from a valid dstateFile (binary data has been converted to
ASCII):
d9:completedd20:.i.?.vk..&.7.....g..i0ee5:peersd20:.i.?.vk..&.
7.....g..
d20:-AZ2504-4PGqC1Tza6WDd2:ip9:127.0.0.13:key8:vkYZ3mwZ4:lefti12415246
5e3:nati0e4:porti35ee20:-
UT1740-..........#.d2:ip9:127.0.0.13:key8:29FA
43C64:lefti37137041e3:nati0e4:porti35eeeee
The above data when you interpret correctly (based on the
TorrentSpecs)
forms a data structure like so:
{ 'completed' => { $shaHashBin => '0' }
'peers' => { $shaHashBin => { $clientID { ip => $ipAddr, key=>
$Key, left=>'0', nat=>'0', port=>$port}
$clientID2 { ip =>
$ipAddr, key=>$Key, left=>'0', nat=>'0', port=>$port}
}
}
}
Unfortunately for some reason $clientID is not being expanded properly
and instead of getting ClientID1/ClientID2/ClientID3 etc and their
associated ip/key/left/nat/port entries, all i get is a
single entry! I'm sure that the old records/entries are being
overwritten by the new entries - so I'm left with a perfectly valid
dstateFile with the last ip:port pair that was read from the file!
I also tried something like so:
$_=<IPFILE>;
chomp;
($ipAddr, $port) = split(/:/);
$clientID = RandomString(20);
$key = RandomString(8);
# dflist file structure.
<SNIP>
while (<IPFILE>) {
chomp;
($ipAddr, $port) = split(/:/);
$clientID = RandomString(20);
$key = RandomString(8);
$completedData->{'peers'}->{$clientID} =
MakeClientHash($ipAddr, $key, $port);
}
This works and the records don;t get overwritten BUT the file format
is broken and i get data like so: d9:completedd20:.i.?.vk..&.
7.....g..i0ee5:peersd20:.i.?.vk..&.7.....g..
d20:-AZ2504-4PGqC1Tza6WDd2:ip9:127.0.0.13:key8:vkYZ3mwZ4:lefti12415246
5e3:nati0e4:porti35eee20:-
UT1740-..........#.d2:ip9:127.0.0.13:key8:29FA
43C64:lefti37137041e3:nati0e4:porti35eeee
Note the (eeee) That's }}}}. There should be 5 of them :( also note
eee20 - that should read ee20 :( Oh, and note: bencode breaks if the
torrentfile is complicated (just in case you actually debug
that).
------------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
#
# Program to create a file called dflist that bttrack.py can
understand.
#use strict;
#use warnings;
use POSIX qw(strftime);
use Getopt::Std;
use URI::Escape 'uri_escape_utf8';
use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
use Convert::Bencode qw(bencode bdecode);
my ($torrentFile, $ipFile, $dflistFile);
my $debug=0;
(my $progname = $0) =~ s|.*/||;
sub UsageError() {
print STDERR "\nusage: $progname torrentFile ipFile dfileName\n";
exit(2);
}
sub FatalError( $ ) {
print STDERR "$progname: @_\n";
exit(1);
}
sub GetRunConfig() {
# If we have more than two arguments signal a error.
UsageError if (@ARGV != 3);
if (@ARGV == 3) { $torrentFile = $ARGV[0];
$ipFile = $ARGV[1];
$dflistFile = $ARGV[2]; }
}
sub ReadFile( $ ) {
my ($pathname) = @_;
local $/;
my $FH;
open($FH, '<', $pathname)
or FatalError("cannot open $pathname for reading: $!");
my $contents = <$FH>;
close $FH;
return $contents;
}
sub WriteFile( $$ ) {
my $FH;
my ($pathname, $contents) = @_;
open($FH, '>', $pathname)
or FatalError("cannot open $pathname for writing: $!");
# Required because we are writing binary data
binmode($FH);
print $FH $contents;
close($FH)
or FatalError("error writing to file $pathname: $!");
}
sub RandomString( $ ) {
my ($lenOfRanStr) = @_;
my @chars=('a'..'z','A'..'Z','0'..'9','_');
my $ranStr;
foreach (1..$lenOfRanStr) {
# rand @chars will generate a random
# number between 0 and scalar @chars
$ranStr .= $chars[rand @chars];
}
return $ranStr;
}
sub MakeClientHash( $$$ ) {
my ($ipAddr, $key, $port) = @_;
return { ip => $ipAddr,
key => $key,
left => '0',
nat => '0',
port => $port };
}
sub CreateDflist {
# Creates a dflist file based on the torrentfile and the
# ipaddress file you provide.
my ($contents, $contentsRef, $shaHashBin, $completedData);
# Read the supplied torrentfile, extract the info values, and compute
# the sha1 hash in binary form ($shaHashBin).
$contents = ReadFile($torrentFile);
$contentsRef = bdecode($contents);
$shaHashBin = sha1(bencode($contentsRef->{'info'}));
my ( $clientID, $ipAddr, $key, $port);
# Read $ipFile and get the $ipAddr:$port pairs for the $torrentFile.
open(IPFILE, $ipFile)
or die "can't open $ipFile: $!";
while(<IPFILE>) {
chomp $_;
($ipAddr, $port) = split(/:/);
$clientID = RandomString(20);
$key = RandomString(8);
# dflist file structure.
$completedData = {
'completed' => { $shaHashBin => '0' },
'peers' => { $shaHashBin => {$clientID =>
MakeClientHash($ipAddr, $key, $port)} }
};
}
# Write dflist data after encoding.
my $encString = bencode($completedData);
WriteFile("$dflistFile", $encString);
print $encString;
}
GetRunConfig;
CreateDflist;
------------------------------
Date: Sun, 16 Sep 2007 08:08:06 -0700
From: "Vivek.M" <vivekm1234@cyberspace.org>
Subject: Re: Problem with my perl script - old records getting over written by new $completedData
Message-Id: <1189955286.440756.66480@g4g2000hsf.googlegroups.com>
Hi, i shortened it. This is the kind of data structure i need to
assign to a anonymous
hash called $completedData. $completedData is passed to bencode to
encode
it and the encoded data is written to disk. (I am a noob at Perl! The
problem just looks complicated..)
Template Data Structure i need to create, that $completedData refers
to: (clientID1,2,3,4 etc..)
This data structure is then encoded by bencode, and put to disk thus
creating a valid file that
bttrack.oy can understand.
{ 'completed' => { $shaHashBin => '0' }
'peers' => { $shaHashBin => { $clientID1 {
ip => $ipAddr, key =>
$Key,
left=>'0', nat=>'0',
port=>$port
}
$clientID2 {
ip =>$ipAddr, key=>
$Key,
left=>'0', nat=>'0',
port=>$port
}
}
}
}
#Perl code i am using (suitably edited for clarity):
sub MakeClientHash( $$$ ) {
my ($ipAddr, $key, $port) = @_;
return { ip => $ipAddr,
key => $key,
left => '0',
nat => '0',
port => $port };
}
sub CreateDflist {
|<SNIP>|
while(<IPFILE>) {
chomp $_;
($ipAddr, $port) = split(/:/);
$clientID = RandomString(20);
$key = RandomString(8);
# dflist file structure.
$completedData = {
'completed' => { $shaHashBin => '0' },
'peers' => { $shaHashBin => {$clientID =>
MakeClientHash($ipAddr, $key, $port)} }
};
}
# Write dflist data after encoding.
my $encString = bencode($completedData);
WriteFile("$dflistFile", $encString);
print $encString;
}
CreateDflist;
The code runs without any errors BUT i get only one valid record on
file - $clientIDXX where XX is the last ip:port pair in file.
------------------------------
Date: Sun, 16 Sep 2007 09:06:10 -0700
From: "Vivek.M" <vivekm1234@cyberspace.org>
Subject: Re: Problem with my perl script - old records getting over written by new $completedData
Message-Id: <1189958770.032537.168510@r29g2000hsg.googlegroups.com>
Hey John, it's working :) :) Yeah! Ugh!! I did it the right way the
first time but i did this:
$completedData->{'peers'}->{$clientID} =
MakeClientHash($ipAddr, $key, $port);
instead of this:
$completedData->{'peers'}->{'shaHashBin'}->{$clientID} =
MakeClientHash($ipAddr, $key, $port);
So my structure got mangled and then i did the other garbage! Many
thanks! Also, a huge thanks to the guys on freenodes #perl who rock!
They told me the same thing :) Needless to say i am very please <g>
Bye
------------------------------
Date: Sun, 16 Sep 2007 10:28:53 -0700
From: "Vivek.M" <vivekm1234@cyberspace.org>
Subject: Re: Problem with my perl script - old records getting over written by new $completedData
Message-Id: <1189963733.797613.151280@y42g2000hsy.googlegroups.com>
err {$shaHashBin}
------------------------------
Date: Sun, 16 Sep 2007 15:48:39 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Problem with my perl script - old records getting over written by new $completedData
Message-Id: <rfcHi.51824$bO6.165@edtnps89>
Vivek.M wrote:
> Hi, i shortened it. This is the kind of data structure i need to
> assign to a anonymous hash called $completedData. $completedData
> is passed to bencode to encode it and the encoded data is written
> to disk. (I am a noob at Perl! The problem just looks complicated..)
>
> Template Data Structure i need to create, that $completedData refers
> to: (clientID1,2,3,4 etc..)
> This data structure is then encoded by bencode, and put to disk thus
> creating a valid file that bttrack.oy can understand.
>
> [ SNIP ]
>
> #Perl code i am using (suitably edited for clarity):
>
> [ SNIP ]
>
> sub CreateDflist {
>
> |<SNIP>|
>
> while(<IPFILE>) {
> chomp $_;
> ($ipAddr, $port) = split(/:/);
>
> $clientID = RandomString(20);
> $key = RandomString(8);
>
> # dflist file structure.
> $completedData = {
> 'completed' => { $shaHashBin => '0' },
> 'peers' => { $shaHashBin => {$clientID =>
> MakeClientHash($ipAddr, $key, $port)} }
> };
You are assigning a single (anonymous) hash for every record in the file which
is why only the last one is saved.
You need to assign values to hash keys instead:
$completedData->{ completed }{ $shaHashBin } = 0;
$completedData->{ peers }{ $shaHashBin }{ $clientID } = MakeClientHash(
$ipAddr, $key, $port );
> }
>
> # Write dflist data after encoding.
> my $encString = bencode($completedData);
> WriteFile("$dflistFile", $encString);
>
> print $encString;
>
> }
>
> CreateDflist;
>
> The code runs without any errors BUT i get only one valid record on
> file - $clientIDXX where XX is the last ip:port pair in file.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Sun, 16 Sep 2007 11:31:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Question on input password on ssh prompt
Message-Id: <l9dvr4-281.ln1@osiris.mauzo.dyndns.org>
Quoth Mav <mluvw47@gmail.com>:
> Hi, all
> I am writing a perl script running on the XP, the machine already
> have openssh installed. The script would call ssh command and send a
> command to the remote host.
> The code like.
<snip>
>
> However right after I made the system call for ssh, it prompts for the
> password.
>
> c:\>perl my.pl
> Invoke command on host : somehost
> enter password: <--- my program stopped right here waiting.
>
> I understood that perl provides pm packages (in this case SSH) to
> get this work done, but the script I am going to run, only will get
> the perl installed and perl.dll, not extra module.
You can use PAR (from CPAN) to package a script plus all dependant
modules up into a single file that can be run with just perl installed.
It's really not worth avoiding the use of modules.
> My question is:
> 1) Is that a way I can feed it the password without install any
> module?, if so, how?
No. However, you can switch to public-key authentication, which doesn't
require you enter the password.
> 2) Or where I can find out more regarding input after prompt
> waiting?
Err... under Unix, the answer is 'use a pty'. I don't know if it is even
possible to emulate this under Win32: it depends on exactly how ssh
prompts for the password.
Ben
------------------------------
Date: Sun, 16 Sep 2007 04:10:49 -0700
From: Sims <Fleischmann.chchch@googlemail.com>
Subject: sqDILJAWOPFIAEGOPIWEGOPIWOP
Message-Id: <1189941049.215353.172970@n39g2000hsh.googlegroups.com>
http://www.rettet-den-affen.de.tl/
------------------------------
Date: Sun, 16 Sep 2007 11:39:28 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: strange behaviour with 'use open IN => ":byte"
Message-Id: <0odvr4-281.ln1@osiris.mauzo.dyndns.org>
Quoth "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>:
> On 09/15/2007 07:06 AM, loopology wrote:
> > If I run this script:
> >
> > #!/usr/bin/perl
> > use open IN => ":byte";
> > use constant A => 1;
> >
> > on a MacBook Pro (Intel)
> >
> > With perl version 5.8.6 (the pre-installed)
> >
> > I get this error:
<snip>
> >
> > if I change the line to:
> > use open IN => ":encoding(UTF16-BE)";
> > I get this error:
> > Unrecognized character \xE0 at /System/Library/Perl/5.8.6/constant.pm
> > line 1.
>
> I'm able to reproduce this behavior on Debian Linux with Perl 5.8.4 and
> Perl 5.9.4.
>
> Note, ":byte" is not correct. The correct layer is ":bytes"; however,
> Perl's reaction to the incorrect layer doesn't produce much clarity for
> the programmer.
In any case, it seems that you should not 'use open' before you use any
other modules: in no case will applying custom PerlIO layers to the
module files produce the correct result. This should probably be
documented in L<open>...
OP: it's probably worth either dropping open altogether, or switching to
an INIT block instead of a BEGIN by replacing
use open IN => ':bytes';
with
INIT {
require open;
open->import(IN => ':bytes');
}
This in then occur later than any 'use' statements (except those in
string evals); note that you will still have to be careful of 'require'
statements executed at runtime.
This could perhaps be considered a bug in Perl: 'require' (or at least
'require MODULE' rather than 'require "FILE"') should probably *not*
honour the default PerlIO layers set by open. This may or may not be
fixable, due to backwards-compatibility...
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 855
**************************************