[32802] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4066 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 29 18:09:42 2013

Date: Tue, 29 Oct 2013 15:09:06 -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           Tue, 29 Oct 2013     Volume: 11 Number: 4066

Today's topics:
        Can this be combined into one statement? <jblack@nospam.com>
    Re: Can this be combined into one statement? <*@eli.users.panix.com>
    Re: Can this be combined into one statement? <jurgenex@hotmail.com>
    Re: Can this be combined into one statement? <rvtol+usenet@xs4all.nl>
    Re: Can this be combined into one statement? <*@eli.users.panix.com>
    Re: Can this be combined into one statement? <rvtol+usenet@xs4all.nl>
    Re: Can this be combined into one statement? <rvtol+usenet@xs4all.nl>
    Re: Can this be combined into one statement? <rvtol+usenet@xs4all.nl>
    Re: Can this be combined into one statement? <rvtol+usenet@xs4all.nl>
    Re: Can this be combined into one statement? <rweikusat@mobileactivedefense.com>
    Re: Can this be combined into one statement? <rweikusat@mobileactivedefense.com>
    Re: Can this be combined into one statement? <jblack@nospam.com>
    Re: Can this be combined into one statement? <jblack@nospam.com>
    Re: Can this be combined into one statement? <hjp-usenet3@hjp.at>
    Re: Can this be combined into one statement? <rweikusat@mobileactivedefense.com>
    Re: Can this be combined into one statement? <jblack@nospam.com>
    Re: Can this be combined into one statement? <ben@morrow.me.uk>
    Re: Can this be combined into one statement? <hjp-usenet3@hjp.at>
    Re: Can this be combined into one statement? <jblack@nospam.com>
    Re: Ping was SIgnal help <ben@morrow.me.uk>
        readdir <gravitalsun@hotmail.foo>
    Re: SIgnal help <derykus@gmail.com>
    Re: Upgrading activestate Perl <bernie@fantasyfarm.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 28 Oct 2013 17:03:25 -0500
From: John Black <jblack@nospam.com>
Subject: Can this be combined into one statement?
Message-Id: <MPG.2cd89b2ceccad1c1989791@news.eternal-september.org>

Simple question I think.  I have a string $line that has some number of fields separated by 
one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
must be a way to write these two lines as one line (skipping the intermediate @line_arr 
step):

   @line_arr = split(/\s+/, $line);
   $file = $line_arr[-1];

but I've tried various syntaxes like:

   $file = split(/\s+/, $line)[-1];

but I have not hit upon a working syntax.  What is it?  Thanks.

John Black


------------------------------

Date: Mon, 28 Oct 2013 22:27:28 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <eli$1310281823@qz.little-neck.ny.us>

In comp.lang.perl.misc, John Black  <jblack@nospam.com> wrote:
>    $file = split(/\s+/, $line)[-1];

So close:

$ perl -wle '$line = "a\tb c\td e\tfilename";
	   $file = (split(/\s+/,$line))[-1];
	   print $file'
filename
$

Elijah
------
does not endorse using other people's domains for spam avoidance


------------------------------

Date: Mon, 28 Oct 2013 15:30:10 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <l9pt69dmqlcmftd1nuvhfca5i4kui9acls@4ax.com>

John Black <jblack@nospam.com> wrote:
>Simple question I think.  I have a string $line that has some number of fields separated by 
>one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
>must be a way to write these two lines as one line (skipping the intermediate @line_arr 
>step):
>
>   @line_arr = split(/\s+/, $line);
>   $file = $line_arr[-1];
>
>but I've tried various syntaxes like:
>
>   $file = split(/\s+/, $line)[-1];

You almost got it:
	$file = (split(/\s+/, $line))[-1];

jue


------------------------------

Date: Tue, 29 Oct 2013 00:50:53 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
To: John Black <jblack@nospam.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <526EF85D.7030800@xs4all.nl>

On 2013-10-28 23:03, John Black wrote:

> Simple question I think.  I have a string $line that has some number of fields separated by
> one or more spaces.  The filename is the last field on the line and I want to grab it.  There
> must be a way to write these two lines as one line (skipping the intermediate @line_arr
> step):
>
>     @line_arr = split(/\s+/, $line);
>     $file = $line_arr[-1];
>
> but I've tried various syntaxes like:
>
>     $file = split(/\s+/, $line)[-1];
>
> but I have not hit upon a working syntax.  What is it?  Thanks.

There are several ways to get there, examples:

   $file = ( split " ", $line )[-1];

   ( $file ) = $line =~ /.*(\S+)/;


-- 
Ruud




------------------------------

Date: Mon, 28 Oct 2013 23:56:32 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <eli$1310281953@qz.little-neck.ny.us>

In comp.lang.perl.misc, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:
> There are several ways to get there, examples:
> 
>    $file = ( split " ", $line )[-1];

$ perl -wle '$line = "a\tb c\td e\tfilename";
	     $file = ( split " ", $line )[-1]; 
	     print $file'        
filename
$

>    ( $file ) = $line =~ /.*(\S+)/;

$ perl -wle '$line = "a\tb c\td e\tfilename";
	     ($file) = $line =~ /.*(\S+)/;
	     print $file'        
e
$ 

Did you actually try your examples?

Elijah
------
also curious if the filename can ever contain whitespace


------------------------------

Date: Tue, 29 Oct 2013 01:01:12 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Can this be combined into one statement?
Message-Id: <526efac8$0$15963$e4fe514c@news2.news.xs4all.nl>

On 2013-10-28 23:03, John Black wrote:

> I have a string $line that has some number of fields separated by
> one or more spaces.  The filename is the last field on the line
> [...] I've tried various syntaxes like:
>
>     $file = split(/\s+/, $line)[-1];
>
> but I have not hit upon a working syntax.  What is it?  Thanks.

There are several ways to get there, examples:

   $file = ( split " ", $line )[ -1 ];

   ( $file ) = $line =~ /.* (\S+) /x;


Also see Text::CSV_XS.

-- 
Ruud




------------------------------

Date: Tue, 29 Oct 2013 01:11:04 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
To: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <526EFD18.6040607@xs4all.nl>

On 2013-10-29 00:56, Eli the Bearded wrote:
> In comp.lang.perl.misc, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:

>>     ( $file ) = $line =~ /.*(\S+)/;
>
> $ perl -wle '$line = "a\tb c\td e\tfilename";
> 	     ($file) = $line =~ /.*(\S+)/;
> 	     print $file'
> e
>
> Did you actually try your examples?

Yeah, but only badly.

   ($file) = $line =~ /.*\s(\S+)/;

-- 
Ruud



------------------------------

Date: Tue, 29 Oct 2013 01:13:08 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Can this be combined into one statement?
Message-Id: <526efd94$0$15967$e4fe514c@news2.news.xs4all.nl>

On 2013-10-29 01:01, Dr.Ruud wrote:
> On 2013-10-28 23:03, John Black wrote:

>    ( $file ) = $line =~ /.* (\S+) /x;

Correction:

      ( $file ) = $line =~ /.*\s (\S+) /x;

-- 
Ruud



------------------------------

Date: Tue, 29 Oct 2013 01:55:49 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
To: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <526F0795.70409@xs4all.nl>

On 2013-10-29 00:56, Eli the Bearded wrote:
> In comp.lang.perl.misc, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:

>>     $file = ( split " ", $line )[-1];
>
> $ perl -wle '$line = "a\tb c\td e\tfilename";
> 	     $file = ( split " ", $line )[-1];
> 	     print $file'
> filename

That works as meant, see "perldoc -f split" about the specialness of a 
single space as the first parameter of split.


But to take the original post literally ("spaces"), it should capture 
"e\tfilename", so then the split should be done with / +/.

-- 
Ruud



------------------------------

Date: Tue, 29 Oct 2013 01:19:29 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <87hac0euvy.fsf@sable.mobileactivedefense.com>

John Black <jblack@nospam.com> writes:
> Simple question I think.  I have a string $line that has some number of fields separated by 
> one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
> must be a way to write these two lines as one line (skipping the intermediate @line_arr 
> step):
>
>    @line_arr = split(/\s+/, $line);
>    $file = $line_arr[-1];
>
> but I've tried various syntaxes like:
>
>    $file = split(/\s+/, $line)[-1];
>
> but I have not hit upon a working syntax.

Grab a sequence of non-whitespace characters anchored at the end of the
string?

$line =~ /(\S+)$/


------------------------------

Date: Tue, 29 Oct 2013 14:10:31 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <87mwlsuq08.fsf@sable.mobileactivedefense.com>

John Black <jblack@nospam.com> writes:
> Simple question I think.  I have a string $line that has some number of fields separated by 
> one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
> must be a way to write these two lines as one line (skipping the intermediate @line_arr 
> step):
>
>    @line_arr = split(/\s+/, $line); [*]
>    $file = $line_arr[-1];
>
> but I've tried various syntaxes like:
>
>    $file = split(/\s+/, $line)[-1]; [**]
>
> but I have not hit upon a working syntax.

Since nobody wrote this so far: The first split call ([*]) runs split in
list context, hence, it returns a list of strings created by it. But the
second ([**]) runs it in scalar context and then, it splits into @_ and
returns the number of fields found in the input.

$file = (split(' ', $line))[-1]

works as intended because the split is evaluated inside a list because
of the outer brackets.


------------------------------

Date: Tue, 29 Oct 2013 10:30:03 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <MPG.2cd990757905b518989792@news.eternal-september.org>

In article <87hac0euvy.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
says...
> 
> John Black <jblack@nospam.com> writes:
> > Simple question I think.  I have a string $line that has some number of fields separated by 
> > one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
> > must be a way to write these two lines as one line (skipping the intermediate @line_arr 
> > step):
> >
> >    @line_arr = split(/\s+/, $line);
> >    $file = $line_arr[-1];
> >
> > but I've tried various syntaxes like:
> >
> >    $file = split(/\s+/, $line)[-1];
> >
> > but I have not hit upon a working syntax.
> 
> Grab a sequence of non-whitespace characters anchored at the end of the
> string?
> 
> $line =~ /(\S+)$/

ooo, nice.  However, if there happens to be any whitespace between the last field and the end 
of the line, I don't think this will work.  But I think the split method would still be ok.  
I don't know if there ever will be any spaces after the filename but probably better to use 
code that would handle it.

John Black


------------------------------

Date: Tue, 29 Oct 2013 10:35:15 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <MPG.2cd991aa2aad96be989793@news.eternal-september.org>

In article <l9pt69dmqlcmftd1nuvhfca5i4kui9acls@4ax.com>, jurgenex@hotmail.com says...
> 
> John Black <jblack@nospam.com> wrote:
> >Simple question I think.  I have a string $line that has some number of fields separated by 
> >one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
> >must be a way to write these two lines as one line (skipping the intermediate @line_arr 
> >step):
> >
> >   @line_arr = split(/\s+/, $line);
> >   $file = $line_arr[-1];
> >
> >but I've tried various syntaxes like:
> >
> >   $file = split(/\s+/, $line)[-1];
> 
> You almost got it:
> 	$file = (split(/\s+/, $line))[-1];
> 
> jue

Thanks all.  This works.  The answer was kind of obvious but I thought I tried that.  Maybe I 
put the first open paren after the split?

John Black


------------------------------

Date: Tue, 29 Oct 2013 17:31:06 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Can this be combined into one statement?
Message-Id: <slrnl6voma.566.hjp-usenet3@hrunkner.hjp.at>

On 2013-10-29 14:10, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> John Black <jblack@nospam.com> writes:
>>    @line_arr = split(/\s+/, $line); [*]
>>    $file = $line_arr[-1];
>>
>> but I've tried various syntaxes like:
>>
>>    $file = split(/\s+/, $line)[-1]; [**]
>>
>> but I have not hit upon a working syntax.
>
> Since nobody wrote this so far: The first split call ([*]) runs split in
> list context, hence, it returns a list of strings created by it. But the
> second ([**]) runs it in scalar context

On my systems (perl 5.8.0 to 5.14.2) the second call doesn't run at all.
It's a syntax error.

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


------------------------------

Date: Tue, 29 Oct 2013 17:02:17 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <878uxc6mee.fsf@sable.mobileactivedefense.com>

John Black <jblack@nospam.com> writes:
> In article <87hac0euvy.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
> says...
>> 
>> John Black <jblack@nospam.com> writes:
>> > Simple question I think.  I have a string $line that has some number of fields separated by 
>> > one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
>> > must be a way to write these two lines as one line (skipping the intermediate @line_arr 
>> > step):
>> >
>> >    @line_arr = split(/\s+/, $line);
>> >    $file = $line_arr[-1];
>> >
>> > but I've tried various syntaxes like:
>> >
>> >    $file = split(/\s+/, $line)[-1];
>> >
>> > but I have not hit upon a working syntax.
>> 
>> Grab a sequence of non-whitespace characters anchored at the end of the
>> string?
>> 
>> $line =~ /(\S+)$/
>
> ooo, nice.  However, if there happens to be any whitespace between the last field and the end 
> of the line, I don't think this will work.

$line =~ /(\S+)\s*$/


------------------------------

Date: Tue, 29 Oct 2013 13:36:56 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <MPG.2cd9bc40af999d50989794@news.eternal-september.org>

In article <878uxc6mee.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
says...
> 
> John Black <jblack@nospam.com> writes:
> > In article <87hac0euvy.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
> > says...
> >> 
> >> John Black <jblack@nospam.com> writes:
> >> > Simple question I think.  I have a string $line that has some number of fields separated by 
> >> > one or more spaces.  The filename is the last field on the line and I want to grab it.  There 
> >> > must be a way to write these two lines as one line (skipping the intermediate @line_arr 
> >> > step):
> >> >
> >> >    @line_arr = split(/\s+/, $line);
> >> >    $file = $line_arr[-1];
> >> >
> >> > but I've tried various syntaxes like:
> >> >
> >> >    $file = split(/\s+/, $line)[-1];
> >> >
> >> > but I have not hit upon a working syntax.
> >> 
> >> Grab a sequence of non-whitespace characters anchored at the end of the
> >> string?
> >> 
> >> $line =~ /(\S+)$/
> >
> > ooo, nice.  However, if there happens to be any whitespace between the last field and the end 
> > of the line, I don't think this will work.
> 
> $line =~ /(\S+)\s*$/

Yep, I thought of this after posting.  Thanks.  I like this.  I bet its faster than using 
split which ends up extracting a bunch of fields that are never used here.

John Black

John Black


------------------------------

Date: Tue, 29 Oct 2013 20:39:53 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Can this be combined into one statement?
Message-Id: <p1j5ka-eg02.ln1@anubis.morrow.me.uk>


Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> 
> Since nobody wrote this so far: The first split call ([*]) runs split in
> list context, hence, it returns a list of strings created by it. But the
> second ([**]) runs it in scalar context and then, it splits into @_

Not any more it doesn't, thank God. This was (finally) removed in 5.12,
but didn't find its way into the perldelta; it's documented in
perl5140delta.

Ben



------------------------------

Date: Tue, 29 Oct 2013 22:09:51 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Can this be combined into one statement?
Message-Id: <slrnl70910.e1m.hjp-usenet3@hrunkner.hjp.at>

On 2013-10-29 18:36, John Black <jblack@nospam.com> wrote:
> In article <878uxc6mee.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
> says...
>> John Black <jblack@nospam.com> writes:
>> > In article <87hac0euvy.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
>> > says...
>> >> John Black <jblack@nospam.com> writes:
>> >> >    @line_arr = split(/\s+/, $line);
>> >> >    $file = $line_arr[-1];
>> >> >
>> >> > but I've tried various syntaxes like:
>> >> >
>> >> >    $file = split(/\s+/, $line)[-1];
[...]
>> 
>> $line =~ /(\S+)\s*$/
>
> Yep, I thought of this after posting.  Thanks.  I like this.  I bet its faster than using 
> split which ends up extracting a bunch of fields that are never used here.

OTOH the regexp probably needs to do a lot of backtracking, so you might
lose that bet. 

Let's see:


#!/usr/bin/perl
use warnings;
use strict;

use Benchmark ':all';

my @lines;

for (1 .. 1000) {
    my $line = "";
    my $nwords = rand(10) + 1;
    for my $iw (1 .. $nwords) {
	$line .= "a" x (rand(10) + 1);
	$line .= " " x (rand(3) + ($iw < $nwords));
    }
    push @lines, $line;
}

cmpthese(-5,
	 {
	    'split' => sub {
			    for my $line (@lines) {
				my $file = (split(/\s+/, $line))[-1];
			    }
		       },
	    'match' => sub {
			    for my $line (@lines) {
				my ($file) = $line =~ /(\S+)\s*$/;
			    }
		       }
	 }
);
__END__

       Rate match split
match 208/s    --  -67%
split 625/s  200%    --


Yup, split is about 3 times faster for this particular set of strings
(may be wildly different for other strings).

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


------------------------------

Date: Tue, 29 Oct 2013 17:07:39 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Can this be combined into one statement?
Message-Id: <MPG.2cd9eda566da39e5989795@news.eternal-september.org>

In article <slrnl70910.e1m.hjp-usenet3@hrunkner.hjp.at>, hjp-usenet3@hjp.at says...
> 
> On 2013-10-29 18:36, John Black <jblack@nospam.com> wrote:
> > In article <878uxc6mee.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
> > says...
> >> John Black <jblack@nospam.com> writes:
> >> > In article <87hac0euvy.fsf@sable.mobileactivedefense.com>, rweikusat@mobileactivedefense.com 
> >> > says...
> >> >> John Black <jblack@nospam.com> writes:
> >> >> >    @line_arr = split(/\s+/, $line);
> >> >> >    $file = $line_arr[-1];
> >> >> >
> >> >> > but I've tried various syntaxes like:
> >> >> >
> >> >> >    $file = split(/\s+/, $line)[-1];
> [...]
> >> 
> >> $line =~ /(\S+)\s*$/
> >
> > Yep, I thought of this after posting.  Thanks.  I like this.  I bet its faster than using 
> > split which ends up extracting a bunch of fields that are never used here.
> 
> OTOH the regexp probably needs to do a lot of backtracking, so you might
> lose that bet. 
> 
> Let's see:
> 
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> use Benchmark ':all';
> 
> my @lines;
> 
> for (1 .. 1000) {
>     my $line = "";
>     my $nwords = rand(10) + 1;
>     for my $iw (1 .. $nwords) {
> 	$line .= "a" x (rand(10) + 1);
> 	$line .= " " x (rand(3) + ($iw < $nwords));
>     }
>     push @lines, $line;
> }
> 
> cmpthese(-5,
> 	 {
> 	    'split' => sub {
> 			    for my $line (@lines) {
> 				my $file = (split(/\s+/, $line))[-1];
> 			    }
> 		       },
> 	    'match' => sub {
> 			    for my $line (@lines) {
> 				my ($file) = $line =~ /(\S+)\s*$/;
> 			    }
> 		       }
> 	 }
> );
> __END__
> 
>        Rate match split
> match 208/s    --  -67%
> split 625/s  200%    --
> 
> 
> Yup, split is about 3 times faster for this particular set of strings
> (may be wildly different for other strings).
> 
> 	hp

This is one of the things I love about math and computers.  You can prove your case.  I stand 
corrected.  My laptop got:

       Rate match split
match 261/s    --  -39%
split 427/s   64%    --

BTW, what is the -5 option doing in the cmpthese function?  I thought the first param was the 
number of iterations, but then negative doesn't make sense?

John Black


------------------------------

Date: Sun, 27 Oct 2013 23:51:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Ping was SIgnal help
Message-Id: <dhl0ka-hpa.ln1@anubis.morrow.me.uk>


Quoth "Dave Saville" <dave@invalid.invalid>:
> On Sun, 27 Oct 2013 12:47:53 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
> 
> > I get the same results, so there's something different about your
> > program which is causing the hang and the failed unpack_sockaddr_in. You
> > will need to start cutting it down until you get something small enough
> > to post.
> 
> As I said in another reply it would seem to the difference between 
> 5.8.2 and 5.16.0

Yes; see below.

> > > And another thing :-)
> > > 
> > > A "real" ping seems to be about once a second here. If I start a ping 
> > > to a host, let it return a few times and pull the ethernet cable it 
> > > obviously stops printing returns.If I then put the cable back it 
> > > starts again. CTRL-C and I get a summary of pings sent, received and 
> > > lost.
> > > 
> > > Trying to do the same thing with Net::Ping and it stops printing 
> > > returns and starts again when I replace the cable - but it sees *no* 
> > > dropped packets. It would appear that it blocks until it gets a 
> > > return. I just tried your program doing the same thing and it hangs at
> > > SENDING PING... until I plug it in again when it takes almost 20 
> > > seconds before it prints ALIVE. 
> > 
> > ping(1) sends ICMP pings by default, which (at least on Unix) require
> > privilege. In order to avoid making you run your script as root,
> > Net::Ping uses TCP 'pings' by default, which actually just attempt a TCP
> > connection to the echo port (port 4) and return 'reachable' if either
> > the connection succeeds or we get a definite ECONNREFUSED. This will
> > lead to different behaviour on failure: in particular, a TCP connection
> > attempt can take several minutes to time out, so if you pull the cable
> > it will take that long before the host is reported dead. The delay when
> > the cable is plugged back in is likely due to the kernel's exponential
> > backoff of connection retries.
> >
> > I don't know what OS/2's security model is like. 
> 
> Hasn't got one :-)
> 
> I *am* using ICMP. My point is "real" ping gets a reject or something 
> when the cable is pulled but keeps trying as when it is plugged in 
> again it not only starts printing status lines immediately but also 
> knows how many failed. I know it is still pinging because the lights 
> on the switch blink.

OK... I don't understand the timeouts, then, but I do understand the
unpack_sockaddr_in failure. Net::ICMP->ping_icmp calls sockaddr_in on
the return value of recv without checking the recv succeeded, and
something is causing recv to fail even after select() has returned
readable. Like you, I can reproduce this with 5.8.2 (with ICMP ping
only), but not with 5.16.3, so something has changed in core perl.

The more I look at the Net::Ping code the less I like it...

> > You could also try Net::Ping::External, though again you will need to
> > patch it for OS/2. (Or, you know, you could just run 'ping -c1' or
> > whatever the equivalent is and check the exit status.)
> 
> LOL that was my first thought. The actual problem I am trying to solve
> is a drop out on VOIP. It has been suggested to run a ping during the 
> call to see if packets are dropping or getting long response times. 
> Ping on its own only gives the packet loss at program end. I wanted it
> continuous and thought running a completely fresh copy of ping every 
> second was a bit much. :-)

Really? ping should be a tiny executable, and OS/2 uses spawn for
process creation so you don't get the fork overhead.

Ben



------------------------------

Date: Wed, 30 Oct 2013 00:06:59 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: readdir
Message-Id: <l4pbi8$1033$1@news.ntua.gr>

is there any way readdir to return me files by modification time ? I do 
not want keep their dates on an array and sort it . I wantone pass like 
ls -ltr


------------------------------

Date: Sun, 27 Oct 2013 15:59:36 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: SIgnal help
Message-Id: <15b7d9f6-0512-4f77-af90-3c6f4aa0957a@googlegroups.com>

On Saturday, October 26, 2013 2:54:01 AM UTC-7, Dave Saville wrote:

   [ ... ] 
> 
> CTRL-C
> 
> Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at D:/u
> 
> sr/lib/perl/lib/5.8.2/os2/Socket.pm line 370.
> 
 
Not to minimize all the nuances but there was a
distinct feeling of "deja vu all over again" on
seeing that particular Socket.pm error. It may be of 
interest to google the message (and some of the early
patches) since it was problematic for Net::Ping and
other modules of that era :)

-- 
Charles DeRykus


------------------------------

Date: Mon, 28 Oct 2013 08:44:30 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Upgrading activestate Perl
Message-Id: <ctms699b8vjhie86h7bsqpr9cc9d2nc7d4@library.airnews.net>

Bernie Cosell <bernie@fantasyfarm.com> wrote:

Just a quick update: I ran my script to get a list of packages to
"reinstall".  Then I uninstalled 5.12 and installed 5.16.  then I installed
all the packages [the .bat file didn't work out quite but simply pasting
the whole list of "ppm instal...." into an admin command prompt did just
fine].  Half hour later, Perl is up, installed, and seems to be working
fine.

Thanks for the help and advice!   /bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 4066
***************************************


home help back first fref pref prev next nref lref last post