[23225] in Perl-Users-Digest
Perl-Users Digest, Issue: 5446 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 5 06:05:53 2003
Date: Fri, 5 Sep 2003 03:05:09 -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 Fri, 5 Sep 2003 Volume: 10 Number: 5446
Today's topics:
[newbie] how to get a element from a hash of array? (fabre)
Re: [newbie] how to get a element from a hash of array? <carsten.nospam@furtherspam.welcomes-you.com>
Re: [newbie] how to get a element from a hash of array? (Sam Holden)
Re: [newbie] how to get a element from a hash of array? <carsten.nospam@furtherspam.welcomes-you.com>
Re: [newbie] how to get a element from a hash of array? <noreply@gunnar.cc>
am a newbie... (Vinod)
Re: am a newbie... (Sam Holden)
Re: Arbitrarily Complex Data Structure (Bryan Castillo)
Bad excel docs with Spreadsheet::WriteExcel::Simple (Erica)
Re: Bad excel docs with Spreadsheet::WriteExcel::Simple (Jay Tilton)
Re: Bad excel docs with Spreadsheet::WriteExcel::Simple (John M. Gamble)
Re: Brackets () in variable used for pattern match (Tad McClellan)
Re: Embedded Perl or Python (XPost) (Cameron Laird)
Re: expression specific search and replace (qanda)
Fax via ISDN-Card, and scanning with multifunctional de <upro@gmx.net>
Re: LWP::UserAgent->request(https) resets alarm() (Charles DeRykus)
Re: Making a script write to a file (take 2) <abigail@abigail.nl>
Re: Net::SSH::Perl <me@here.com>
Re: Net::SSH::Perl (Anno Siegel)
Net::Telnet and waitfor context problem <jim.mozley@exponential-e.com>
Re: Net::Telnet and waitfor context problem (Anno Siegel)
Pb with IO::Socket::INET and recv <sppNOSPAM@monaco377.com>
Re: Perl6 internals Archives? (John M. Gamble)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Sep 2003 07:03:55 +0100
From: pedro.fabre@gen.gu.se (fabre)
Subject: [newbie] how to get a element from a hash of array?
Message-Id: <pedro.fabre-0509030703550001@192.168.0.5>
being my script:
#! /usr/bin/perl -w
use strict;
my %hash = (
'one' => "A B C D",
'two' => "I J K L",
);
foreach my $key (keys %hash){
print "$hash{$key}\n";
}
How I can get "K", the third value for key two?
thanks in advance
P
------------------------------
Date: Fri, 05 Sep 2003 08:12:42 +0200
From: Carsten Aulbert <carsten.nospam@furtherspam.welcomes-you.com>
Subject: Re: [newbie] how to get a element from a hash of array?
Message-Id: <bj99i4$ge96k$1@uni-berlin.de>
Hi
fabre wrote:
> my %hash = (
> 'one' => "A B C D",
> 'two' => "I J K L",
> );
>
First, this is not an hash of arrays, but just an "ordinary" hash where
each key points to a string.
> foreach my $key (keys %hash){
> print "$hash{$key}\n";
> }
>
>
> How I can get "K", the third value for key two?
Starting from your example, I'd recommend split /\s+/, $hash{$key}.
If you really want a hash of arrays (untested):
#reference to hash of arrays
my $hash = {'one' => "A B C D",'two' => "I J K L"};
#output
foreach my $key (keys %$hash) {
foreach my $elem (@{$hash->{$key}}) {
print "$elem ";
}
print "\n";
}
HTH
CA
------------------------------
Date: 5 Sep 2003 06:25:14 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: [newbie] how to get a element from a hash of array?
Message-Id: <slrnblgb24.j1k.sholden@flexal.cs.usyd.edu.au>
On Fri, 05 Sep 2003 08:12:42 +0200,
Carsten Aulbert <carsten.nospam@furtherspam.welcomes-you.com> wrote:
>
> If you really want a hash of arrays (untested):
>
> #reference to hash of arrays
> my $hash = {'one' => "A B C D",'two' => "I J K L"};
my $hash = { 'one' => [qw/A B C D/], 'two' => [qw/I J K L/]};
Might be better...
--
Sam Holden
------------------------------
Date: Fri, 05 Sep 2003 08:29:34 +0200
From: Carsten Aulbert <carsten.nospam@furtherspam.welcomes-you.com>
Subject: Re: [newbie] how to get a element from a hash of array?
Message-Id: <bj9aho$ge4ku$1@uni-berlin.de>
Sam Holden wrote:
>>#reference to hash of arrays
>>my $hash = {'one' => "A B C D",'two' => "I J K L"};
>
>
> my $hash = { 'one' => [qw/A B C D/], 'two' => [qw/I J K L/]};
>
> Might be better...
>
ouch, thank you, to early and too much copy&paste and not enough brain
left, please refill ;-)
Thanks again
CA
------------------------------
Date: Fri, 05 Sep 2003 08:54:27 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [newbie] how to get a element from a hash of array?
Message-Id: <bj9c31$gdvl2$1@ID-184292.news.uni-berlin.de>
Sam Holden wrote:
> On Fri, 05 Sep 2003 08:12:42 +0200,
> Carsten Aulbert <carsten.nospam@furtherspam.welcomes-you.com> wrote:
>
>>If you really want a hash of arrays (untested):
>>
>>#reference to hash of arrays
>>my $hash = {'one' => "A B C D",'two' => "I J K L"};
>
> my $hash = { 'one' => [qw/A B C D/], 'two' => [qw/I J K L/]};
>
> Might be better...
Of course, the hash doesn't _need_ to be anonymous:
#hash of array references
my %hash = ( one => [qw/A B C D/], two => [qw/I J K L/] );
#output
foreach my $key (keys %hash) {
foreach my $elem (@{$hash{$key}}) {
print "$elem ";
}
print "\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 4 Sep 2003 21:38:35 -0700
From: vchamarty@yahoo.com (Vinod)
Subject: am a newbie...
Message-Id: <bccc1210.0309042038.589b2353@posting.google.com>
hi!!
I am a beginner with Perl. am rtying to use the repetition feature as
in -
print 'a'x5;
would print 'aaaaa'
I am trying to use it with regular expressions.
I am trying to replace an occurence of 'there' with 'aaaaa' but I dont
want to put it there explicitly.
I am trying something like....
s/there/'a'x5/;
which doesnt work.
Can someone give me some sort of an escape sequence...?
Thank you
Vinod
------------------------------
Date: 5 Sep 2003 04:44:16 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: am a newbie...
Message-Id: <slrnblg550.hkc.sholden@flexal.cs.usyd.edu.au>
On 4 Sep 2003 21:38:35 -0700, Vinod <vchamarty@yahoo.com> wrote:
> hi!!
>
> I am trying something like....
>
> s/there/'a'x5/;
>
> which doesnt work.
>
> Can someone give me some sort of an escape sequence...?
s/there/'a'x5/e;
or:
$replace = 'a'x5;
s/there/$replace/;
The replacement is a quoted string, not an expression.
See perldoc perlop for details on what /e does.
--
Sam Holden
------------------------------
Date: 5 Sep 2003 00:02:21 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Arbitrarily Complex Data Structure
Message-Id: <1bff1830.0309042302.6ef90fc8@posting.google.com>
Vlad Tepes <minceme@start.no> wrote in message news:<bj7tln$pdr$1@troll.powertech.no>...
> JR <jrolandumuc@yahoo.com> wrote:
>
> >jrolandumuc@yahoo.com (JR) wrote in message news:<b386d54b.0308291231.4ca368cd@posting.google.com>...
> >>Brian McCauley <nobull@mail.com> wrote in message news:<u97k4xen8c.fsf@wcl-l.bham.ac.uk>...
> >>> jrolandumuc@yahoo.com (JR) writes:
> >>>
> >>>> Hi. Is it possible to create a subroutine to handle an arbitrarily
> >>>> complex data structure (for my purposes, complex only refers to hashes
> >>>> and arrays)?
>
> I just palyed some small with tarversing. Maybe yo like to have a loko:
>
> sub processitem($) {
> my $indent = shift;
> my $item = shift || $_;
> print "$indent ", " " x $indent, $item, "\n";
> }
>
> sub trav(@); # must declare sub to prototype recurs. func.
>
> sub trav {
> my $i = ref $_[0] ? 0 : 1 + shift; # indentation
> foreach ( @_ ) {
> /HASH/ && do{ trav $i, %$_; next };
> /ARRAY/ && do{ trav $i, @$_; next };
> /CODE/ && do{ trav $i, $_->(); next };
> /REF/ && do{ trav $i, $$_ ; next };
> processitem $i;
> }
> }
>
> trav \%hoh, \\\\\%hah, \%hah, \%heh;
>
# DON'T TRY DOING THIS THOUGH!
# fyi Data::Dumper handles it
my $a = { name => 'bryan', age => 26 };
$a->{evil_death} = $a;
trav($a);
> Cherio,
------------------------------
Date: 4 Sep 2003 21:40:41 -0700
From: google_ng@coffin.org (Erica)
Subject: Bad excel docs with Spreadsheet::WriteExcel::Simple
Message-Id: <3dca4528.0309042040.a44bf4f@posting.google.com>
I've been trying to create an excel document with
SpreadSheet::WriteExcel::Simple on Windows 2000 Server, and open it
with MS Excel 7.0 (old, I know, but all my more recent copies seem to
be on bad CDs).
A 6.0 KB file is created, but when I try open the Excel file in Excel
I get an error, "Cannot access xxx.xls."
This is what I'm doing:
use Spreadsheet::WriteExcel::Simple;
$ss = Spreadsheet::WriteExcel::Simple->new;
@headings = ("One", "Two", "Three");
@headings = ("1", "2", "3");
$ss->write_bold_row(\@headings);
$ss->write_row(\@data);
open FILE, ">xxx.xls";
print FILE $ss->data;
close FILE;
Does anyone have any ideas about what I might be doing wrong?
Thanks,
Erica
------------------------------
Date: Fri, 05 Sep 2003 05:37:19 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Bad excel docs with Spreadsheet::WriteExcel::Simple
Message-Id: <3f581f44.196677011@news.erols.com>
google_ng@coffin.org (Erica) wrote:
: I've been trying to create an excel document with
: SpreadSheet::WriteExcel::Simple on Windows 2000 Server, and open it
: with MS Excel 7.0 (old, I know, but all my more recent copies seem to
: be on bad CDs).
: A 6.0 KB file is created, but when I try open the Excel file in Excel
: I get an error, "Cannot access xxx.xls."
:
: This is what I'm doing:
: use Spreadsheet::WriteExcel::Simple;
:
: $ss = Spreadsheet::WriteExcel::Simple->new;
: @headings = ("One", "Two", "Three");
: @headings = ("1", "2", "3");
: $ss->write_bold_row(\@headings);
: $ss->write_row(\@data);
: open FILE, ">xxx.xls";
: print FILE $ss->data;
: close FILE;
:
: Does anyone have any ideas about what I might be doing wrong?
An Excel worksheet file contains binary data.
binmode() the filehandle before writing.
------------------------------
Date: Fri, 5 Sep 2003 08:15:27 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Bad excel docs with Spreadsheet::WriteExcel::Simple
Message-Id: <bj9gmv$gbe$4@e250.ripco.com>
In article <3f581f44.196677011@news.erols.com>,
Jay Tilton <tiltonj@erols.com> wrote:
>google_ng@coffin.org (Erica) wrote:
>
>: I've been trying to create an excel document with
>: SpreadSheet::WriteExcel::Simple on Windows 2000 Server, and open it
>: with MS Excel 7.0 (old, I know, but all my more recent copies seem to
>: be on bad CDs).
>: A 6.0 KB file is created, but when I try open the Excel file in Excel
>: I get an error, "Cannot access xxx.xls."
>:
>: This is what I'm doing:
>: use Spreadsheet::WriteExcel::Simple;
>:
>: $ss = Spreadsheet::WriteExcel::Simple->new;
>: @headings = ("One", "Two", "Three");
>: @headings = ("1", "2", "3");
>: $ss->write_bold_row(\@headings);
>: $ss->write_row(\@data);
>: open FILE, ">xxx.xls";
>: print FILE $ss->data;
>: close FILE;
>:
>: Does anyone have any ideas about what I might be doing wrong?
>
>An Excel worksheet file contains binary data.
>binmode() the filehandle before writing.
>
Also, i suspect the second @headings assignment was meant to be
a @data assignment. I know, i'm critiquing an example, but just
in case.
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: Thu, 4 Sep 2003 20:05:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <slrnblfobd.2hn.tadmc@magna.augustmail.com>
William Hymen <t18_pilot@hotmail.spam.com> wrote:
> I get tired of constantly scrolling to the bottom ;) - Bill
You do not need to scroll to the bottom when followups are
composed properly.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 05 Sep 2003 09:03:32 -0000
From: claird@lairds.com (Cameron Laird)
Subject: Re: Embedded Perl or Python (XPost)
Message-Id: <vlgkb4dtchna9e@corp.supernews.com>
In article <c907a3eba2b531449c8dc7a212285911@news.teranews.com>,
Chris <rebel@removethis.rebel.com.au> wrote:
.
.
.
>I am developing a software project where a major portion of it is to
>enable script access to c++ classes
>
>The idea is to extend the basic functionality of the program by allowing
>third parties to write add ons that are called by my c++ classes as
>virtual functions.
.
.
.
>Given the above which interpreter is most likely to fit my bill with the
>smallest footprint ?
.
.
.
Let's be clear on what we're discussing. When you write,
"smallest footprint", do you seriously mean, "creates the
smallest differential in the size of the resulting exe-
cutable image"? Frankly, that would surprise me; your
project sounded interesting and useful up until those
last two words. I don't mean to be harsh; unless there's
something you're not telling us, though, the size of
executables-as-file-images is quite unlikely to be even
the tenth most important aspect of your target.
I'll anticipate a bit more, and observe that Python is
likely to be the better choice, because it remains easier
for a newcomer to extend-or-embed (it's not clear that
you've decided between these alternatives), at least until
Perl 6 meets all its goals.
--
Cameron Laird <Cameron@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
------------------------------
Date: 4 Sep 2003 23:29:46 -0700
From: fumail@freeuk.com (qanda)
Subject: Re: expression specific search and replace
Message-Id: <62b4710f.0309042229.67f91a8@posting.google.com>
Thanks Tad, as always you make me look at things in a different way.
If we extend the data ...
__DATA__
field1,ABC/ab12cd ef34,field3,field4,EFC/ab12cd ef56,field6
field1,XBC/ab12cd ef34,field3,field4,EFC/ab13cd ef56,field6
field1,YBC/ab12cd ef34,field3,field4,EFC/ab13ce ef56,field6
field1,YBC/ab13cd ef34,field3,field4,EFC/ab13ce ef56,field6
field1,YBC/ab14cd ef34,field3,field4,EFC/ab13ce ef56,field6
field1,YBC/ab14cd ef34,field3,field4,EFC/ab13ce ef56,field6
field1,YBC/ab14cd ef34,field3,field4,EFC/ab13ce ef56,field6
field1,YBC/ab14cd ef34,field3,field4,EFC/ab13ce ef56,field6
The result is ...
field1,ABC/string_1 ef34,field3,field4,EFC/string_1 ef56,field6
field1,XBC/string_1 ef34,field3,field4,EFC/string_2 ef56,field6
field1,YBC/string_1 ef34,field3,field4,EFC/string_3 ef56,field6
field1,YBC/string_2 ef34,field3,field4,EFC/string_4 ef56,field6
field1,YBC/string_3 ef34,field3,field4,EFC/string_5 ef56,field6
field1,YBC/string_4 ef34,field3,field4,EFC/string_6 ef56,field6
field1,YBC/string_5 ef34,field3,field4,EFC/string_7 ef56,field6
field1,YBC/string_6 ef34,field3,field4,EFC/string_8 ef56,field6
However the unique parts and their replacements should be ...
all C/ab12cd replaced by string_1
all C/ab13cd replaced by string_2
all C/ab13ce replaced by string_3
all C/ab14cd replaced by string_4
Thanks again.
------------------------------
Date: Fri, 05 Sep 2003 10:06:53 +0200
From: upro <upro@gmx.net>
Subject: Fax via ISDN-Card, and scanning with multifunctional device
Message-Id: <877k4nslpe.fsf@lux99.localhost>
Hi there!
Some 10 days ago I convinced a Windows hardliner to switch to Linux
completely!
Basically he was pissed off by virusses (I think he got SOBIG or
something similar). I got him to by a pack of SuSE 8.1 and installed
it for him.
I myself do use Slackware, since years, and I love it because of ots
ease, clarity and because of the absence of anything line linuxconf or
yast, tools which INHO never really do what they should. linuxconf was
real crap until I stopped to use RedHat at the company (7.0
then). yast/yast2 seems better, and anyway there's no other way for a
newbie who doesn't want to get into linux computing, but who wants to
remain a plain "user". So I am not really proficient in the SuSE
way...
Well, so far everything works for him: Banking, printing, DSL
internet, e-mail, DVD, TV etc. but he needs two more things: fax and
scanning.
Now this is a prob for me, because he has a somewhat strange config:
He has no modem, only an ISDN card, and he uses a HP OfficeJet (I
think the model is K60 or similar, I don't have it in fromt of me. DId
I mention my froend is some 800 km away?)
I installed efax, and he has also hylafax. I have no clue how to get
this ISDN card to send faxes. No ISDN at my place, no DSL, no
multifunctional device etc.
I also do have no clue about how to get scaning to work with his
OfficeJet. Yast searches for USB os SCSI scanners, but his device is
connected via parport, as it is a parallel printer...
Any help in getting his fax and scanner to work is greatly
appreciated!
Hope to hear from ya!
--
Michael
r-znvy: zvpunry.wryqra jro.qr (chg gur "@" jurer vg svgf...)
ab fcnz cyrnfr
------------------------------
Date: Fri, 5 Sep 2003 05:46:44 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: LWP::UserAgent->request(https) resets alarm()
Message-Id: <HKq81w.ELr@news.boeing.com>
In article <16df376.0309041846.42a003fc@posting.google.com>,
jarkun <christophergoebel@yahoo.com> wrote:
>found a bug in LWP. When calling LWP::UserAgent->request(https)
>any pre-existing alarm() gets reset. Digging around the problem
>appears that the LWP uses NET::SSL.pm as part of the https connection
>and this code uses an alarm() for timeouts
>
>This doesn't happen for plain ol http-style connections, only https
>
>I haven't puzzled out which piece needs to be changed SSL.pm or LWP
>
>This is happening on a redhat9 box with what I believe are all the
>latest packages from CPAN
>
>Who do I contact to submit this as a bug report?
>
Hm, I'm using alarms successfully with LWP (2.001),
Crypt-SSLeay (0.51), and openssl 0.9.6g.
[ Crypt::SSLeay includes Net::SSL ]
Are you sure you're using the latest versions?
HTH,
--
Charles DeRykus
------------------------------
Date: 05 Sep 2003 09:12:48 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Making a script write to a file (take 2)
Message-Id: <slrnblgksg.6g7.abigail@alexandra.abigail.nl>
Dave (prometheus_au@excite.com.au) wrote on MMMDCLVII September MCMXCIII
in <URL:news:526e114e.0309041747.7f0ec8aa@posting.google.com>:
// G'day all
//
// I'm trying to get a script to write (append) data to the bottom line
// of a text file (*.dat). I know the variables I want to add but can't
// do it.
// I need to append something that looks like this...
//
// $invoice|$date|Your Order has been received
//
// Any suggestions would be helpful.
What have you tried so far?
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)}; # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Fri, 5 Sep 2003 06:45:07 +0000 (UTC)
From: "get-fuzzy" <me@here.com>
Subject: Re: Net::SSH::Perl
Message-Id: <bj9bdj$291$1@visp.bt.co.uk>
Sorry, I cant comment on the perl as yet but, are you not in the least bit
worried that someone might hack into your base system - get the unencrypted
password (old password) then log on - using ssh to the other box ?
ssh is not 100% flawless
From a security point of view it is a nightmare, from a SA point of view - I
can see where you are coming from !
Just curious is all
"blob" <jaws@skyinet.net> wrote in message news:3f57f2ae@news.skyinet.net...
> Hi all,
>
> Below is my script that will be used to connect to a remote host and
> change my password automatically:
>
> ===========================================
> #!/usr/bin/perl
>
>
> use strict();
> use Net::SSH::Perl;
>
>
> $user="jaws";
> $pass="password";
> $host="xxx.xxx.xxx.xxx";
> $old_password="password";
> $new_password="newpass";
>
>
> my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
> $ssh->login($user, $pass);
>
>
> $ssh->register_handler("stderr", sub {
> my($channel, $buffer) = @_;
> my $str = $buffer->bytes;
>
>
> if ($str eq "Enter login password: ") {
> $channel->send_data($old_password);
> }
>
>
> elsif ($str eq "New password: ") {
> $channel->send_data($new_password);
> }
>
> elsif ($str eq "Re-enter new password: ") {
> $channel->send_data($new_password);
> }
> });
> $ssh->cmd('passwd');
> ==========================================
>
> After running the program, my password didnt changed I was still able to
> connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
>
> Thanks.
>
> Jaws
>
------------------------------
Date: 5 Sep 2003 09:05:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Net::SSH::Perl
Message-Id: <bj9jkr$434$1@mamenchi.zrz.TU-Berlin.DE>
<chesucat@freeshell.org> wrote in comp.lang.perl.misc:
> In comp.lang.perl.misc blob <jaws@skyinet.net> wrote:
> b>Hi all,
> b>
> b>Below is my script that will be used to connect to a remote host and
> b>change my password automatically:
> b>
> b>===========================================
> b>#!/usr/bin/perl
> b>
> b>
> b>use strict();
> b>use Net::SSH::Perl;
> b>
> <snipped>
> b>Does anybody has an idea what's missing or wrong with my script?
> b>
>
> I didn't know strict was functions?
It is not, but the call "use strict()" doesn't have any effect.
The part in "()" is interpreted as an import list to the strict pragma
(which is technically a module). Since it is empty, strict's import
function isn't called, and no strictures are activated.
This is unlikely to be the cause of the OPs problem, but it doesn't
bode well for the rest of the code.
Anno
------------------------------
Date: Fri, 5 Sep 2003 09:56:45 +0100
From: "Jim Mozley" <jim.mozley@exponential-e.com>
Subject: Net::Telnet and waitfor context problem
Message-Id: <bj9j4e$gr272$1@ID-201189.news.uni-berlin.de>
I have seen a problem using Net::telnet that I can work around but cannot
explain.
I use the following for wait for a particular pattern match in the input
stream:
$session->waitfor(Match => '/mymatch/',
Errmode => 'return')
or die "cannot match it", $session->lastline;
This is as shown in an example in the module documentation.
The only way I can get this to actually die is to use the default errmode
(which is die). If I use error mode return or my own error handling
subroutine the test is always true even when it should not (I have used
input_log and dump_log to check the input).
The way I can get round this is to use a test in a list context e.g.
($prematch, $match) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $match ) {
print "found it\n";
} else {
print "did not find it\n";
}
or even
($ok) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $ok ) {
etc.
What I was originally trying to do was something along the lines of:
unless ( $result = $session->waitfor('/match/') ) {
print "failed to match \"match\" before timeout";
etc.
}
or even
unless ( $session->waitfor('/match/') ) {
etc.
and as a result of trying to work out why this was not working for me
discovered the "context problem". Can anyone explain what I'm doing wrong?
Rather than work on a larger program (where I discovered the problem) I have
replicated this in a much smaller script where I have aimed to follow the
module examples as near as possible, but I still see the issue.
Regards,
Jim
------------------------------
Date: 5 Sep 2003 09:46:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Net::Telnet and waitfor context problem
Message-Id: <bj9m2f$879$1@mamenchi.zrz.TU-Berlin.DE>
Jim Mozley <jim.mozley@exponential-e.com> wrote in comp.lang.perl.misc:
> I have seen a problem using Net::telnet that I can work around but cannot
> explain.
>
> I use the following for wait for a particular pattern match in the input
> stream:
>
> $session->waitfor(Match => '/mymatch/',
> Errmode => 'return')
> or die "cannot match it", $session->lastline;
>
> This is as shown in an example in the module documentation.
>
> The only way I can get this to actually die is to use the default errmode
> (which is die). If I use error mode return or my own error handling
> subroutine the test is always true even when it should not (I have used
> input_log and dump_log to check the input).
I cannot reproduce this. This
use Net::Telnet;
my $t = Net::Telnet->new( 'localhost') or die;
$t->waitfor( Match => '/mymatch/', Errmode => 'return') or
die "timeout";
dies with "timeout" every time. Perl 5.8.0, Net::Telnet 3.03
Anno
------------------------------
Date: Fri, 05 Sep 2003 09:50:55 +0200
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <sppNOSPAM@monaco377.com>
Subject: Pb with IO::Socket::INET and recv
Message-Id: <3f584065$0$26400$626a54ce@news.free.fr>
Hi all,
Since I migrate a client program to Mandrake 9.1 (kernel 2.4.21-0.13) and
perl 5.8.0, this little program didn't work.
The problem occured on the
unless(recv...) line
It always return me "false" => my program think that there was an error.
If I remove the unless (recv...) check, it seems to work.
Thanks in advance for any kind of help.
Sébastien
#!/usr/bin/perl -w
use IO::Socket;
use IO::Select;
use strict;
my $end_car="\r";
my $time_out_sending = my $time_out_receiving = 30;
my @recep = &envoie("Hello, How are you","192.168.0.1","45678","");
foreach (@recep){ print "$_\n"}
exit;
sub envoie {
my $to_send = $_[0];
my $adr_ip= $_[1];
my $por = $_[2];
my $socket='';
#=========================/ Socket creation \=========================
unless ($socket = IO::Socket::INET->new(PeerAddr=> $adr_ip,
PeerPort=> $por,
Proto=> "tcp",
Timeout=>10,
Type=> SOCK_STREAM))
{
return "Cannot connect to $adr_ip:$por $@";
}
my $s=IO::Select->new();
$s->add($socket);
#==========================/ Sending \================================
if ($s->can_write($time_out_sending)){
unless ($socket->send("$to_send"."$end_car",'')){ #>>>> SENDING
$s->remove($socket);
close($socket);
return "Cannot Send $!";
}
}
else { #------------> Time out <-------------
$s->remove($socket);
close($socket);
return "TIME OUT sending datas";
}
#=========================/ Receiving \===============================
my $data_read="";
if ($s->can_read($time_out_receiving)){
unless ($socket->recv($data_read,'1024')){ #<<<<< PROB HERE
$s->remove($socket); # Always executed
close($socket); # " "
return "Cannot Receive $!"; # " "
}
$s->remove($socket);
close($socket);
return $data_read;
}
else { #------------> Time out <-------------
$s->remove($socket);
close($socket);
return "TIME OUT receiving datas";
}
}
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
------------------------------
Date: Fri, 5 Sep 2003 08:12:41 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Perl6 internals Archives?
Message-Id: <bj9ghp$gbe$3@e250.ripco.com>
In article <d81ecffa.0309032118.54bc5d8e@posting.google.com>,
trwww <toddrw69@excite.com> wrote:
>jgamble@ripco.com (John M. Gamble) wrote in message
>news:<bj5clt$gob$1@e250.ripco.com>...
>> I used to drop in occasionally at the perl6-internals archive at
>> http://archive.develooper.com/ to see how development was going.
>>
>> The entries seem to have vanished past 2002, and nothing new
>> is posted. Has the archive moved? If so, where to?
>
>You can find the archive of all newsgroups on nntp.perl.org at:
>
>http://groups.google.com/groups?group=perl
>
>the archive of perl.perl6.internals is at:
>
>http://groups.google.com/groups?group=perl.perl6.internals
>
Thanks. I hadn't expected the group to not have the comp.lang. prefix,
so i missed it. And http://www.parrotcode.org/ still refers to the
broken archive.
Thanks again,
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
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.
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 5446
***************************************