[25369] in Perl-Users-Digest
Perl-Users Digest, Issue: 7614 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 6 14:05:29 2005
Date: Thu, 6 Jan 2005 11:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 6 Jan 2005 Volume: 10 Number: 7614
Today's topics:
Advice please on stripping non-printing characters <no@spam.please>
ANNOUNCE: Time::Out 0.01 <patrick.leboutillier@gmail.com>
Re: Cant return multiple hashes from subroutine <richard@zync.co.uk>
Re: Cant return multiple hashes from subroutine <tadmc@augustmail.com>
CPAN troubles (Was: Re: How to set the baud rate on a s arkadyz1@yahoo.com
dns querry script. (Ali Ataman)
Re: dns querry script. <mritty@gmail.com>
Re: dns querry script. <mritty@gmail.com>
Re: dns querry script. <1usa@llenroc.ude.invalid>
Re: dns querry script. <graham.drabble@lineone.net>
Re: Dummy regex question <1usa@llenroc.ude.invalid>
Re: Dummy regex question <tadmc@augustmail.com>
Re: Dummy regex question <sbryce@scottbryce.com>
Is it correct that strict and warnings will not apply t ioneabu@yahoo.com
Re: Is it correct that strict and warnings will not app <mritty@gmail.com>
Re: Line continuation in Perl <abigail@abigail.nl>
Re: match regex split <bik.mido@tiscalinet.it>
Re: Net::SSH::Perl - remoteinteract.pl doesn?t work <news@chaos-net.de>
Re: Net::SSH::Perl - remoteinteract.pl doesn?t work <1usa@llenroc.ude.invalid>
Re: Newbie question: "Get substring of line" <bik.mido@tiscalinet.it>
perl crash on sucking $socket into array imahacker@the-pentagon.com
Re: perl crash on sucking $socket into array <1usa@llenroc.ude.invalid>
Re: perl crash on sucking $socket into array imahacker@the-pentagon.com
Re: perl crash on sucking $socket into array <1usa@llenroc.ude.invalid>
Re: perl crash on sucking $socket into array <tadmc@augustmail.com>
Re: trouble with passing reference of hash. xhoster@gmail.com
Re: unix commands project? <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Jan 2005 18:48:27 GMT
From: J Taylor <no@spam.please>
Subject: Advice please on stripping non-printing characters
Message-Id: <3k1rt09nd65i3fag10enjhp4oknn2eu9l8@4ax.com>
Hi!
I've seen various examples of stripping non-printing (and non-ascii)
chars from a string with something like this:
$string =~ s/[\000-\037]/ /g;
I've chosen to strip all but the printable ascii chars (using hex):
$string =~ s/[^\x20-\x7f]/ /g;
This *seems* to work better for my purposes, I'm wondering though if are
gotchas I'm missing.
Thanks.
------------------------------
Date: Tue, 4 Jan 2005 22:30:29 GMT
From: "patl" <patrick.leboutillier@gmail.com>
Subject: ANNOUNCE: Time::Out 0.01
Message-Id: <I9ws24.10tq@zorch.sf-bay.org>
Hi,
Here's a small module to help with timeouting long running
operations...
[Also in the CPAN -- Randal]
------------------------------------------------------------------------
Time::Out - Easy timeouts
=========================
use Time::Out ;
# Time out the following code block after 5 seconds
timeout 5 => affects {
# do something that might take a long time...
} ;
if ($@){
# timeout occured...
}
INSTALLATION
Note: Your system must support alarm(2).
To install this module type the following:
perl Makefile.PL
make
make test
make install
COPYRIGHT AND LICENCE
Copyright (C) 2005 Patrick LeBoutillier
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
------------------------------
Date: Thu, 06 Jan 2005 16:08:11 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: Cant return multiple hashes from subroutine
Message-Id: <pan.2005.01.06.16.08.11.540127@zync.co.uk>
On Thu, 06 Jan 2005 16:06:07 +0000, Richard Gration wrote:
> ^
> print "sales: $hashh->{'sales_calc_total'}\n";
> ^^
Mistake, should be
> print "sales: $hashr1->{'sales_calc_total'}\n";
------------------------------
Date: Thu, 6 Jan 2005 10:46:17 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Cant return multiple hashes from subroutine
Message-Id: <slrnctqqqp.9ee.tadmc@magna.augustmail.com>
sam <sam.wun@authtec.com> wrote:
> The following code only return a single hash:
No it doesn't.
Subroutines in Perl return a "list".
> return (%values, %valuesB);
That returns a list of all of the key/value pairs from %values
followed by all of the key/value pairs from %valuesB.
You cannot tell where the "boundary" between the 2 are.
> my(%hashh, %hashhB) = construct;
> print Dumper(%hashh);
> print "sales: $hashh{'sales_calc_total'}\n";
> I've been scratching my head for whole day but couldn't found a way to
> fix it.
You need to return a (2-element) list of references instead of
smushing together all of the key/value pairs.
return (\%values, \%valuesB); # take references
...
my($h, $hB) = construct; # save references returned
print Dumper($h); # no de-referencing required
print "sales: $h->{'sales_calc_total'}\n"; # de-reference the hash
> It does look simple, but it turns out killing me completely. :(
perdoc perlreftut
perdoc perlref
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Jan 2005 10:58:19 -0800
From: arkadyz1@yahoo.com
Subject: CPAN troubles (Was: Re: How to set the baud rate on a serial port (Perl under cygwin)?)
Message-Id: <1105037899.913993.32530@f14g2000cwb.googlegroups.com>
Paul Lalli wrote:
> <arkadyz1@yahoo.com> wrote in message
> news:1104954134.833672.172170@z14g2000cwz.googlegroups.com...
> > I'm not sure if it's the right group for this question as it's very
> > environment-specific.
> > Actually, the subject "How to set the baud rate on a serial port
(Perl
> > under cygwin)?" says it all.
>
> A search for 'SerialPort' at search.cpan.org turns up a number of
likely
> candidates. Have you seen any of those? Can you explain in what way
> they do not meet your needs?
>
> Paul Lalli
Thanks for the advice.
It looks like Win32::SerialPort does all I need. Unfortunately, I
can't install it. At some point, I get a message "No 'Makefile' will
be created" and it's pretty much the end of installation - the rest of
the messages just complain about the lack of makefile.
What am I doing wrong?
Thanks in advance,
Arkady.
Here is the full session log:
$ cpan -i Win32::SerialPort
CPAN: Storable loaded ok
Going to read /cygdrive/c/arkady/.cpan/Metadata
Database was generated on Wed, 05 Jan 2005 08:51:16 GMT
Running install for module Win32::SerialPort
Running make for B/BB/BBIRTH/Win32-SerialPort-0.19.tar.gz
CPAN: Digest::MD5 loaded ok
CPAN: Compress::Zlib loaded ok
Checksum for
/cygdrive/c/arkady/.cpan/sources/authors/id/B/BB/BBIRTH/Win32-SerialPort-0.19.tar.gz
ok
Scanning cache /cygdrive/c/arkady/.cpan/build for sizes
SerialPort-0.19/
SerialPort-0.19/README
SerialPort-0.19/Changes
SerialPort-0.19/README.txt
SerialPort-0.19/Makefile.PL
SerialPort-0.19/MANIFEST
SerialPort-0.19/Altport.pm
SerialPort-0.19/t/
SerialPort-0.19/t/test1.t
SerialPort-0.19/t/test2.t
SerialPort-0.19/t/test3.t
SerialPort-0.19/t/test4.t
SerialPort-0.19/t/test5.t
SerialPort-0.19/t/test6.t
SerialPort-0.19/t/test7.t
SerialPort-0.19/lib/
SerialPort-0.19/lib/Win32API/
SerialPort-0.19/lib/Win32API/CommPort.pm
SerialPort-0.19/lib/Win32/
SerialPort-0.19/lib/Win32/SerialPort.pm
SerialPort-0.19/eg/
SerialPort-0.19/eg/any_os.plx
SerialPort-0.19/eg/demo1.plx
SerialPort-0.19/eg/demo2.plx
SerialPort-0.19/eg/demo3.plx
SerialPort-0.19/eg/demo4.plx
SerialPort-0.19/eg/demo5.plx
SerialPort-0.19/eg/demo6.plx
SerialPort-0.19/eg/demo7.plx
SerialPort-0.19/eg/demo8.plx
SerialPort-0.19/eg/demo9.plx
SerialPort-0.19/eg/options.plx
SerialPort-0.19/eg/stty.plx
SerialPort-0.19/html/
SerialPort-0.19/html/Win32/
SerialPort-0.19/html/Win32/SerialPort.html
SerialPort-0.19/html/Win32API/
SerialPort-0.19/html/Win32API/CommPort.html
Removing previously used /cygdrive/c/arkady/.cpan/build/SerialPort-0.19
CPAN.pm: Going to build B/BB/BBIRTH/Win32-SerialPort-0.19.tar.gz
Creating new t/DefaultPort.pm
Win32::SerialPort and Win32API::CommPort
VERSION 0.19
No 'Makefile' will be created
Test with: perl test.pl
Install with: perl install.pl
Test with nothing connected to COM1
or for different port: perl test.pl PORT
Timeout tests can take up to 30 seconds per test
Creating new test.pl
Creating new install.pl
make: *** No targets specified and no makefile found. Stop.
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
make had returned bad status, install seems impossible
------------------------------
Date: 6 Jan 2005 09:36:32 -0800
From: serhant@doruk.net.tr (Ali Ataman)
Subject: dns querry script.
Message-Id: <5831e321.0501060936.70eceb0a@posting.google.com>
Hi everyone.
I have a script that should read a file line by line and make a querry
for each of these domains in the file but it won't work. Can anyone
tell me where the problem might be?
Thanx.
#!/usr/bin/perl -w
$file = '/domlist'; # Name the file
open(INFO, $file); # Open the file
foreach (<INFO>) {
use Net::DNS;
my $res = Net::DNS::Resolver->new;
my @mx = mx($res,"$_");
if (@mx) {
foreach $rr (@mx) {
print $rr->preference, " ", $rr->exchange, "\n";
}
} else {
warn "Can't find MX records for $_: ", $res->errorstring, "\n";
}
close(INFO);
}
------------------------------
Date: Thu, 06 Jan 2005 17:53:10 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: dns querry script.
Message-Id: <aWeDd.23555$fe5.20373@trndny06>
"Ali Ataman" <serhant@doruk.net.tr> wrote in message
news:5831e321.0501060936.70eceb0a@posting.google.com...
> Hi everyone.
>
> I have a script that should read a file line by line and make a querry
> for each of these domains in the file but it won't work.
That is a remarkably poor error description. What is the expected
output, and how does the actual output differ?
> Can anyone
> tell me where the problem might be?
>
>
>
> #!/usr/bin/perl -w
you forgot
use strict;
and
use warnings;
is better than -w
> $file = '/domlist'; # Name the file
> open(INFO, $file); # Open the file
it is better to use lexical filehandles than bareword filehandles, and
always, always, *always* check the return value of open().
open my $info, $file or die "Cannot open $file: $!";
> foreach (<INFO>) {
>
> use Net::DNS;
> my $res = Net::DNS::Resolver->new;
> my @mx = mx($res,"$_");
useless use of double-quotes. please see
perldoc -q quoting
> if (@mx) {
> foreach $rr (@mx) {
> print $rr->preference, " ", $rr->exchange, "\n";
> }
> } else {
> warn "Can't find MX records for $_: ", $res->errorstring, "\n";
> }
> close(INFO);
> }
You need to tell us exactly *how* your program isn't working before
anyone can reliably tell you *why* it isn't working.
Paul Lalli
------------------------------
Date: Thu, 06 Jan 2005 18:07:26 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: dns querry script.
Message-Id: <y7fDd.24139$152.9852@trndny01>
"Ali Ataman" <serhant@doruk.net.tr> wrote in message
news:5831e321.0501060936.70eceb0a@posting.google.com...
>
> #!/usr/bin/perl -w
> $file = '/domlist'; # Name the file
> open(INFO, $file); # Open the file
> foreach (<INFO>) {
My previous advice not-withstanding, I'm willing to bet that the
absolute cause of your error is that you forgot to chomp the domain
here. You're trying to get info about (for example) "amazon.com\n"
instead of "amazon.com". Add the line:
chomp;
Paul Lalli
------------------------------
Date: 6 Jan 2005 18:07:44 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: dns querry script.
Message-Id: <Xns95D685907D7B4asu1cornelledu@132.236.56.8>
serhant@doruk.net.tr (Ali Ataman) wrote in
news:5831e321.0501060936.70eceb0a@posting.google.com:
> I have a script that should read a file line by line and make a querry
> for each of these domains in the file but it won't work. Can anyone
> tell me where the problem might be?
>
> Thanx.
>
>
>
> #!/usr/bin/perl -w
use warnings;
is preferable.
Also, you are missing
use strict;
Please read the posting guidelines for this group before going any
further.
> $file = '/domlist'; # Name the file
Useless comments like this are neither necessary nor helpful.
> open(INFO, $file); # Open the file
Always check if open succeeded. Also, I prefer to use the 3-argument form
of open and lexical filehandles:
open my $INFO, '<', $file or die "Cannot open $file: $!";
However, for the purposes of posting in this group, it would be better if
you put some sample data in the __DATA__ section of your script.
> foreach (<INFO>) {
Better to process the file one line at a time:
while(<INFO>) {
> use Net::DNS;
There is no point in putting this inside your loop.
> my $res = Net::DNS::Resolver->new;
> my @mx = mx($res,"$_");
Useless use of quotes. But more importantly, $_ probably has a newline at
the end.
>
> if (@mx) {
> foreach $rr (@mx) {
> print $rr->preference, " ", $rr->exchange, "\n";
> }
> } else {
> warn "Can't find MX records for $_: ", $res->errorstring, "\n";
> }
> close(INFO);
> }
Always reduce your scripts to the smallest possible program that still
displays the problem. So, for example, if you had tried:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Net::DNS;
my @mx = mx 'unur.com';
print Dumper \@mx;
__END__
C:\Dload> perl dns.pl
$VAR1 = [
bless( {
'preference' => 5,
'rdlength' => 9,
'ttl' => 86400,
'name' => 'unur.com',
'class' => 'IN',
'type' => 'MX',
'rdata' => ' ??root+?',
'exchange' => 'root.unur.com'
}, 'Net::DNS::RR::MX' )
];
and seen that it produces the output you wanted, you would have known
that the problem lay in the reading of domain names from the file as the
following version demonstrates:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Net::DNS;
while(<DATA>) {
my @mx = mx $_;
print Dumper \@mx;
}
__DATA__
unur.com
C:\Dload> perl dns.pl
$VAR1 = [];
$VAR1 = [];
A few seconds of head scratching would then have enabled you to realize
that you forgot to chomp the data you read:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Net::DNS;
while(<DATA>) {
chomp;
next unless $_;
my @mx = mx $_;
print Dumper \@mx;
}
__DATA__
unur.com
C:\Dload> perl dns.pl
$VAR1 = [
bless( {
'preference' => 5,
'rdlength' => 9,
'ttl' => 86194,
'name' => 'unur.com',
'class' => 'IN',
'type' => 'MX',
'rdata' => ' ??root+?',
'exchange' => 'root.unur.com'
}, 'Net::DNS::RR::MX' )
];
Now, reading the posting guidelines and following the suggestions in that
document would have enabled you to solve the problem on your own. So,
please go ahead, and read that document.
Sinan
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Thu, 06 Jan 2005 18:26:24 GMT
From: Graham Drabble <graham.drabble@lineone.net>
Subject: Re: dns querry script.
Message-Id: <Xns95D6BB9566CB3grahamdrabblelineone@ID-77355.user.dfncis.de>
On 06 Jan 2005 serhant@doruk.net.tr (Ali Ataman) wrote in
news:5831e321.0501060936.70eceb0a@posting.google.com:
> Hi everyone.
>
> I have a script that should read a file line by line and make a
> querry for each of these domains in the file but it won't work.
> Can anyone tell me where the problem might be?
Doesn't work is a rather poor error message. Problems I've spotted
just looking through quickly are:
#!/usr/bin/perl -w
use strict; #then declare variables using my
use warnings; # is better than -w
# Code is easier to maintain if you indent blocks.
my $file = '/domlist'; # Name the file
open(INFO, $file); # Open the file
foreach (<INFO>) {
use Net::DNS; # This should probably be outside the loop.
my $res = Net::DNS::Resolver->new;
my @mx = mx($res,"$_");
if (@mx) {
foreach my $rr (@mx) {
print $rr->preference, " ", $rr->exchange, "\n";
}
} else {
warn "Can't find MX records for $_: ", $res->errorstring,
"\n";
}
close(INFO); # You're closing the file having read one line.
# Move this to the end of the script or delete it
# completely as perl will close files for you.
}
--
Graham Drabble
If you're interested in what goes on in other groups or want to find
an interesting group to read then check news.groups.reviews for what
others have to say or contribute a review for others to read.
------------------------------
Date: 6 Jan 2005 16:19:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Dummy regex question
Message-Id: <Xns95D6733A486E3asu1cornelledu@132.236.56.8>
"JayEs" <not@home.net> wrote in
news:1ScDd.12717$iC4.7894@newssvr30.news.prodigy.com:
>> This is, of course, perfectly valid (it doesn't actually help the OP,
>> because the OP didn't give accurate information about his problem).
>> And there are, of course, more than one ways to do it. In general
...
> How much more accurate do I need to be?
>
> * I asked a question with a clear description of the problem: How to
> split string that contains a space.
Clearly, however, the string you were trying to split did not contain a
space but , the HTML entity for 'non breaking space'.
> * Proposed solution didn't do the job,
The proposed solution did the job for the problem you described.
> * Not due to not giving inaccurate information, but due to
> the problem being obfuscated by an idiosyncracy of the OS
It has nothing to do with the OS. means 'non-breaking space'. As
such, HTML::Entities converts it to "\240" not a space character.
> I don't think that saying I didn't give accurate information is
> entirely fair...
It is more than fair, and your resistance to learning is astounding me.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Thu, 6 Jan 2005 10:38:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dummy regex question
Message-Id: <slrnctqqbo.9ee.tadmc@magna.augustmail.com>
JayEs <not@home.net> wrote:
>> because the OP didn't give accurate information about his problem).
> * I asked a question with a clear description of the problem: How to split
> string that contains a space.
But that was *not* your problem, as you have seen.
So it was inaccurate.
> I don't think that saying I didn't give accurate information is entirely
> fair...
There is no concept of "fair" when discussing _facts_.
The Nameless quote above (please provide an attribution when you
quote someone) was not about _you_ it was about the _information_.
The information was clearly inaccurate, a factual truth.
> Then again, problem is solved (thanks Mr, Bryce) so all is well that ends
> well.
Bugs are most often a slap-the-forehead I-sure-do-feel-silly
type of thing. Get used to it. :-)
Nameless did not say anything about you, Nameless (this is getting
tedious) said something about the facts that were presented.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 06 Jan 2005 10:50:15 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Dummy regex question
Message-Id: <Zu-dnXR-k73S50DcRVn-jA@comcast.com>
JayEs wrote:
> How much more accurate do I need to be?
You are missing the point. The reason that the first few responses did
not solve your problem was that you did not know what the problem
actually was. Therefore your problem description was not accurate.
> * I asked a question with a clear description of the problem: How to split
> string that contains a space.
But that wasn't really what you wanted to do.
> * Proposed solution didn't do the job,
Proposed solution split on a space. That is what you had asked for.
> after
> some discussion Scott figured out what the problem was after I gave the NG a
> code sample reproducing the problem. *
I figured out what the problem description really was. I suspected that
you did not really want to split on a space, but on something else. The
key was to find out what that something else was.
> Not due to not giving inaccurate information,
Your information was inaccurate. You said you wanted to split on a
space. That wasn't what you really wanted to do.
> but due to the problem being obfuscated by an idiosyncracy of
> the OS (or so it seems).
No. Due to your not taking the time to find out what the problem really
was. That's OK. That is what debugging is a lot of the time.
So don't get defensive. Learn from the mistake. Next time a split
doesn't work as expected, double check the contents of the variable you
are splitting. And next time you post to this NG, include a short, but
complete program that demonstrates the problem. The key to solving the
problem was finding out what the problem was. Without your code, we
couldn't do that.
------------------------------
Date: 6 Jan 2005 09:30:43 -0800
From: ioneabu@yahoo.com
Subject: Is it correct that strict and warnings will not apply to checking the code in MYCLASS?
Message-Id: <1105032643.677549.309810@f14g2000cwb.googlegroups.com>
if I put
use strict;
use warnings;
use MYCLASS;
at the top of my program, is it correct that strict and warnings will
not apply to checking the code in MYCLASS? I did not know about this
and missed a big error using a global instead of a lexical. When I put
them in my class/module file, the error was picked up.
It may sound dumb but maybe worth mentioning.
wana
------------------------------
Date: Thu, 06 Jan 2005 17:45:42 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Is it correct that strict and warnings will not apply to checking the code in MYCLASS?
Message-Id: <aPeDd.23554$fe5.3910@trndny06>
<ioneabu@yahoo.com> wrote in message
news:1105032643.677549.309810@f14g2000cwb.googlegroups.com...
> if I put
>
> use strict;
> use warnings;
> use MYCLASS;
>
> at the top of my program, is it correct that strict and warnings will
> not apply to checking the code in MYCLASS? I did not know about this
> and missed a big error using a global instead of a lexical. When I
put
> them in my class/module file, the error was picked up.
> It may sound dumb but maybe worth mentioning.
strict and warnings are lexically scoped, and for good reason. Imagine
a module author who's code 'works' but is not strict-compliant, and/or
generates warnings. It would be very bad for the user of such a module
to be able to break the module simply by using strict and/or warnings in
his own code. Worse would be if the user of such a module was *unable*
to use the module without disabling strict and warnings in his own code.
When creating a module, you should put
use strict;
use warnings;
near the top of the .pm file (right under the package declaration).
See also:
perldoc warnings
for some features that are helpful to module authors.
Paul Lalli
------------------------------
Date: 31 Dec 2004 01:24:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Line continuation in Perl
Message-Id: <slrnct9aia.h3.abigail@alexandra.abigail.nl>
Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMMCXXXIX September
MCMXCIII in <URL:news:vks7t01l56b1dt7ta89300jv4c23ohupq1@4ax.com>:
,, On 29 Dec 2004 20:36:57 GMT, Abigail <abigail@abigail.nl> wrote:
,,
,, >-: things. OTOH you will be able to modify the grammar the way you like
,, >-: most, which is not that bad after all. (And I bet you will do, BTW!)
,, [snip]
,, >Beside that I don't think it's going to be feasable to change such
,, >significant parsing rules, I don't think it's a smart thing to do, even
,, >if it's possible. If every one is going to create his/her language, with
,, >significant different syntax, it's going to be very hard to cooperate.
,, >Would you want to maintain programs where every author used his/her
,, >language? Would you bother producing patches for CPAN modules if every
,, >author used his/her own language?
,,
,, This is a serious concern many people share with you. But somehow it
,, surprises me that you're concerned in the first place, as I though you
,, were rather inclined to apply patches to current perls and I remember
,, you wrote quite a few articles about portability not being a thing
,, about which to be just as mad as some people are.
The only patches I apply to my perls are the 'dor' patch - which will
be in 5.10 anyway, and a patch to turn off certain kinds of warnings.
But for any code that's intended to run outside my own computers (like
work related stuff), I won't use '//' or 'err' operators. And I turn
warnings off with 'no warnings "syntax".
As for not caring too much about portability just comes from the
observation a lot of code (probably the majority of the code) only
targets a limited number of computers - typically one. It doesn't
mean it's not important - it just means that you don't have to bring
up portability on every little program discussed on Usenet.
Having said that, I fail to see what portability between platforms
has to do with maintaining code.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Thu, 06 Jan 2005 19:37:40 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: match regex split
Message-Id: <audqt0letd6jgkq5cdt5rpk518ppp0qkcu@4ax.com>
On 5 Jan 2005 20:09:21 -0800, "MisterX" <89esprit@gmail.com> wrote:
>The script thus far:
>
>while (<LOGFILE>)
>{
>if ($_=~/Server date/ || /Total number of bytes/ || /Elapsed
>processing time/ || /Elapsed processing time/)
>{
>($_=~ s/^\s+//);
>print $_;
>}
>}
As a side note: (i) it's preferrable to adopt an effective indenting
style, (ii) the whole point of $_ is to be implicit when possible.
Thus your snippet may look like:
while (<LOGFILE>) {
next unless /Server date/ ||
/Total number of bytes/ ||
/Elapsed processing time/ ||
/Elapsed processing time/;
s/^\s+//;
print;
}
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 6 Jan 2005 16:46:00 +0000 (UTC)
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Net::SSH::Perl - remoteinteract.pl doesn?t work
Message-Id: <slrnctqqq8.ctc.news@saturn.maki.dom>
* A. Sinan Unur wrote:
> My first suggestion is to stop posting so many almost identical messages
> in such a short period of time.
O.k. - sorry for that.
>
> Now, a natural question occurs to me: Did you run the script with debug
> enabled (as it is in the version available on CPAN)?
>
> If you did, why don't provide that information?
>
Here it is:
---
saturn:~/20_perl/ssh martin$ ./remoteinteract_voyager.pl
saturn.maki.dom: Reading configuration data ~/.ssh/config
saturn.maki.dom: Reading configuration data /etc/ssh_config
saturn.maki.dom: Connecting to voyager, port 22.
saturn.maki.dom: Remote protocol version 1.99, remote software version
OpenSSH_3.6.1p1+CAN-2004-0175
saturn.maki.dom: Net::SSH::Perl Version 1.25, protocol version 1.5.
saturn.maki.dom: No compat match: OpenSSH_3.6.1p1+CAN-2004-0175.
saturn.maki.dom: Connection established.
saturn.maki.dom: Waiting for server public key.
saturn.maki.dom: Received server public key (768 bits) and host key
(1024 bits).
Argument "ssh-rsa" isn't numeric in numeric eq (==) at
/System/Library/Perl/5.8.1/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line
4.
saturn.maki.dom: Host 'voyager' is known and matches the host key.
saturn.maki.dom: Encryption type: DES3
saturn.maki.dom: Sent encrypted session key.
saturn.maki.dom: Received encryption confirmation.
saturn.maki.dom: RSA authentication failed: Can't load public key.
saturn.maki.dom: Doing challenge response authentication.
saturn.maki.dom: No challenge presented.
saturn.maki.dom: Trying password authentication.
saturn.maki.dom: Sending command: passwd
saturn.maki.dom: Entering interactive session.
match 1
---
If I should post the whole script (30 lines), please let me know
>
> Please read the posting guidelines ...
>
O.k. - I now did.
--
Epur Si Muove (Gallileo Gallilei)
------------------------------
Date: 6 Jan 2005 17:47:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Net::SSH::Perl - remoteinteract.pl doesn?t work
Message-Id: <Xns95D6821B07A94asu1cornelledu@132.236.56.8>
Martin Kissner <news@chaos-net.de> wrote in
news:slrnctqqq8.ctc.news@saturn.maki.dom:
> * A. Sinan Unur wrote:
>> Did you run the script with debug enabled (as it is in the
>> version available on CPAN)?
> Here it is:
> ---
> saturn:~/20_perl/ssh martin$ ./remoteinteract_voyager.pl
> saturn.maki.dom: Reading configuration data ~/.ssh/config
> saturn.maki.dom: Reading configuration data /etc/ssh_config
> saturn.maki.dom: Connecting to voyager, port 22.
> saturn.maki.dom: Remote protocol version 1.99, remote software version
> OpenSSH_3.6.1p1+CAN-2004-0175
> saturn.maki.dom: Net::SSH::Perl Version 1.25, protocol version 1.5.
> saturn.maki.dom: No compat match: OpenSSH_3.6.1p1+CAN-2004-0175.
> saturn.maki.dom: Connection established.
> saturn.maki.dom: Waiting for server public key.
> saturn.maki.dom: Received server public key (768 bits) and host key
> (1024 bits).
> Argument "ssh-rsa" isn't numeric in numeric eq (==) at
> /System/Library/Perl/5.8.1/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line
> 4.
> saturn.maki.dom: Host 'voyager' is known and matches the host key.
> saturn.maki.dom: Encryption type: DES3
> saturn.maki.dom: Sent encrypted session key.
> saturn.maki.dom: Received encryption confirmation.
> saturn.maki.dom: RSA authentication failed: Can't load public key.
> saturn.maki.dom: Doing challenge response authentication.
> saturn.maki.dom: No challenge presented.
> saturn.maki.dom: Trying password authentication.
> saturn.maki.dom: Sending command: passwd
> saturn.maki.dom: Entering interactive session.
>
> match 1
> ---
> If I should post the whole script (30 lines), please let me know
I am assuming we are still talking about the snippet you posted earlier:
>> Martin Kissner <news@chaos-net.de> wrote in
>> news:slrnctqjaa.cp0.news@saturn.maki.dom:
>>
>>> ...
>>> if ($str =~ /password/) {
>>> print "\n\tmatch 1\n";
Question: Which one of the following lines causes the behavior you are
seeing?
>>> my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
>>> $packet->put_str($old_password);
>>> $packet->send;
I would either use the debugger or insert some good old fashioned print
statements after each of the lines above to check that.
I went ahead and installed everything involved on the FreeBSD system I have
access to and tested the remoteinteract.pl script on my shell account with
my hosting provider. The remote password was successfully changed.
Here is the script as I tested it:
asu1@xxx:~ > perl -v
This is perl, v5.8.5 built for i386-freebsd-64int
asu1@xxx:~ > cat remoteinteract.pl
#!/usr/bin/perl
use constant HOST => 'example.com';
use constant USER => 'dummy';
use constant NEWPASS => 'newpass';
use constant OLDPASS => 'oldpass';
use strict;
use warnings;
use Net::SSH::Perl;
use Net::SSH::Perl::Constants qw( :msg );
my $ssh = Net::SSH::Perl->new(HOST, debug => 1);
$ssh->login(USER, OLDPASS);
$ssh->register_handler(SSH_SMSG_STDERR_DATA, sub {
my($ssh, $packet) = @_;
my $str = $packet->get_str;
if ($str =~ /^\(current\) UNIX password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(OLDPASS);
$packet->send;
}
elsif ($str =~ /^New password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}
elsif ($str =~ /^Retype new password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}
});
$ssh->cmd('passwd');
__END__
asu1@xxx:~ > perl remoteinteract.pl
xxx.xxx.xxx.xxx: Reading configuration data /home/asu1/.ssh/config
xxx.xxx.xxx.xxx: Reading configuration data /etc/ssh_config
xxx.xxx.xxx.xxx: Connecting to example.com, port 22.
xxx.xxx.xxx.xxx: Remote protocol version 1.99, remote software version
OpenSSH_3.1p1
xxx.xxx.xxx.xxx: Net::SSH::Perl Version 1.23, protocol version 1.5.
xxx.xxx.xxx.xxx: No compat match: OpenSSH_3.1p1.
xxx.xxx.xxx.xxx: Connection established.
xxx.xxx.xxx.xxx: Waiting for server public key.
xxx.xxx.xxx.xxx: Received server public key (768 bits) and host key (1024
bits).
xxx.xxx.xxx.xxx: Host 'example.com' is known and matches the host key.
xxx.xxx.xxx.xxx: Encryption type: DES3
xxx.xxx.xxx.xxx: Sent encrypted session key.
xxx.xxx.xxx.xxx: Received encryption confirmation.
xxx.xxx.xxx.xxx: RSA authentication failed: Can't load public key.
xxx.xxx.xxx.xxx: Doing challenge response authentication.
xxx.xxx.xxx.xxx: No challenge presented.
xxx.xxx.xxx.xxx: Trying password authentication.
xxx.xxx.xxx.xxx: Sending command: passwd
xxx.xxx.xxx.xxx: Entering interactive session.
>>> (current) UNIX password:
>>> New password:
>>> Retype new password:
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Thu, 06 Jan 2005 19:37:36 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Newbie question: "Get substring of line"
Message-Id: <780rt0l0gbdsd35nadpq6sr2epmrvdqa9t@4ax.com>
On Wed, 5 Jan 2005 18:38:36 -0500, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:
>>>> (my $str=$_) =~ s/.*=//; # e.g.
>> ^^^^^^
>> ^^^^^^
>>
>>>Isn't that a little more work than is necessary? (And perhaps a bit
>>>greedy,
[snip]
>"e.g." wasn't the issue, though.
"e.g." was the issue in the sense that it was meant to clearly
underline that what I was proposing was nothing but one out of many
WTDI.
>Well how about a benchmark:
>
>use Benchmark;
>
>my $good = q!$_ = 'abc=123'; (my $str=$_) =~ s/.*=//;!;
>my $bad = q! my $str = $1 if ...
Pardon me, but what is the point of posting an incomplete snippet like
that? IMHO you'd better either stop at "how about a benchmark?" or at
least show the actual code you tried.
However there's another thread going on in which at a certain point
Uri Guttman explains why such a benchmark would be neverthelessly
flawed.
Here's a non-flawed benchmark:
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/:all :hireswallclock/;
timethis -60, sub {
$_='abc=123';
(my $str=$_) =~ s/.*=//;
}, 'all';
__END__
all: 61.13 wallclock secs (61.13 usr + 0.00 sys = 61.13 CPU)
@ 460505.27/s (n=28150687)
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/:all :hireswallclock/;
timethis -60, sub {
$_='abc=123';
my $str = $1 if /[^=]+=(.*)/;
}, 'all';
__END__
all: 64.81 wallclock secs (64.81 usr + 0.00 sys = 64.81 CPU)
@ 242270.85/s (n=15701574)
This is under Windows. Under Linux I get:
all: 63.953 wallclock secs (63.95 usr + 0.00 sys = 63.95 CPU)
@ 733928.82/s (n=46934748)
and
all: 62.8004 wallclock secs (62.80 usr + 0.00 sys = 62.80 CPU)
@ 313567.79/s (n=19692057)
respectively.
PS: yes, I _slightly_ edited the output (not the figures!) for
clarity.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 6 Jan 2005 08:12:41 -0800
From: imahacker@the-pentagon.com
Subject: perl crash on sucking $socket into array
Message-Id: <1105027961.402967.122410@z14g2000cwz.googlegroups.com>
The following code has crashed every machine i have tried it on except
for the original one i wrote it on. (3 out of 4 boxes) All are freshly
formatted with activestate installed. The program is perl/tk if that
makes a diff. i have also bundled it with perl2exe, and it crashes in
the same way. The program just "stops responding."
I have isolated the problem to the @line=<$ocket> line. If i comment
this line out, the script works as expected, but this is undesirable.
I would like to have the mail transfer information stored in a var.
putting the @line=<$ocket> AFTER the close($ocket) also fixes the
problem, but perl warns me that I am trying to read a socket has
already been closed, and doesnt store the information. Any help or
pointers in the right direction would be greatly appreciated, as i am
fairly new to perl.
$hostmail="mail.domain.net";
chomp($hostmail);
@message='
This is my email message.
';
$ocket = IO::Socket::INET->new(
PeerAddr => "$hostmail",
PeerPort => "25") || die "could not connect to $host: $!\n";
print $ocket "delo domain.net\n";
print $ocket "MAIL FROM: me\@domain.net\n";
print $ocket "RCPT TO: addy\@domain.net\n";
print $ocket "DATA\n";
print $ocket 'From: "nickname" <addy@domain.net>';
print $ocket "\n";
print $ocket "To: <addy\@domain.net>\n";
print $ocket "Subject: subject here\n\n";
print $ocket "@message";
print $ocket "\n.\nQUIT\n";
close($ocket);
@line=<$ocket>;
print "@line";
------------------------------
Date: 6 Jan 2005 16:23:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl crash on sucking $socket into array
Message-Id: <Xns95D673F35D86Fasu1cornelledu@132.236.56.8>
imahacker@the-pentagon.com wrote in news:1105027961.402967.122410
@z14g2000cwz.googlegroups.com:
> I have isolated the problem to the @line=<$ocket> line.
See
perldoc -f shutdown
> $hostmail="mail.domain.net";
> chomp($hostmail);
>
> @message='
> This is my email message.
> ';
>
> $ocket = IO::Socket::INET->new(
> PeerAddr => "$hostmail",
> PeerPort => "25") || die "could not connect to $host: $!\n";
> print $ocket "delo domain.net\n";
> print $ocket "MAIL FROM: me\@domain.net\n";
> print $ocket "RCPT TO: addy\@domain.net\n";
Yuck!
See
http://search.cpan.org/~gbarr/libnet-1.19/Net/SMTP.pm
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: 6 Jan 2005 08:29:38 -0800
From: imahacker@the-pentagon.com
Subject: Re: perl crash on sucking $socket into array
Message-Id: <1105028978.570670.194160@z14g2000cwz.googlegroups.com>
Hey, thank you - that was very helpful, just what i needed to know :)
------------------------------
Date: 6 Jan 2005 16:33:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl crash on sucking $socket into array
Message-Id: <Xns95D675A4328A9asu1cornelledu@132.236.56.8>
imahacker@the-pentagon.com wrote in news:1105028978.570670.194160
@z14g2000cwz.googlegroups.com:
> Hey, thank you - that was very helpful, just what i needed to know :)
>
You are welcome.
There are other modules on CPAN for handling incoming or outgoing email.
You might want to browse:
http://search.cpan.org/
There is also FAQ on this:
http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlfaq9/How_do_I_send_mail.html
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Thu, 6 Jan 2005 11:23:08 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl crash on sucking $socket into array
Message-Id: <slrnctqsvs.9j4.tadmc@magna.augustmail.com>
imahacker@the-pentagon.com <imahacker@the-pentagon.com> wrote:
> $hostmail="mail.domain.net";
> chomp($hostmail);
Why attempt to remove a newline when it is not possible
that there even _is_ a newline?
> @message='
> This is my email message.
> ';
> PeerAddr => "$hostmail",
perldoc -q vars
What's wrong with always quoting "$vars"?
So:
PeerAddr => $hostmail,
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 06 Jan 2005 18:49:28 GMT
From: xhoster@gmail.com
Subject: Re: trouble with passing reference of hash.
Message-Id: <20050106134928.300$sY@newsreader.com>
sam <sam.wun@authtec.com> wrote:
> Hi,
>
> I m trying to pass the reference of a hash variable to subroutine's
> subroutine, but I found no record being passed to the function. Here is
> the actual code:
use strict or die;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 6 Jan 2005 10:48:04 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: unix commands project?
Message-Id: <slrnctqqu4.9ee.tadmc@magna.augustmail.com>
hymie! <hymie@lactose.smart.net> wrote:
> I could have sworn that there was a project at one point to replace
> the "basic" Unix commands (ls, mv, cp, stuff like that) with perl
> scripts.
>
> Can somebody remind me if this project still exists, and where I might
> find it?
Perl Power Tools:
http://ppt.perl.org/
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 V10 Issue 7614
***************************************