[25139] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7388 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 10 11:05:32 2004

Date: Wed, 10 Nov 2004 08:05:06 -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           Wed, 10 Nov 2004     Volume: 10 Number: 7388

Today's topics:
    Re: 'stat' and it's exceptions (Anno Siegel)
    Re: 'stat' and it's exceptions <bik.mido@tiscalinet.it>
    Re: 'stat' and it's exceptions <bik.mido@tiscalinet.it>
        [OT] Re: braindead languages? <1usa@llenroc.ude.invalid>
    Re: better way using IO::Select and pool of non-blockig <and11@rol.ru>
    Re: better way using IO::Select and pool of non-blockig <usenet_05_08_2004@stuartmoore.org.uk>
    Re: better way using IO::Select and pool of non-blockig <usenet_05_08_2004@stuartmoore.org.uk>
    Re: call pperl from c++ passing token list (Charlie)
        Difficulty with slice of referenced array <lawshouse.public@btconnect.com>
    Re: Difficulty with slice of referenced array (Anno Siegel)
    Re: Difficulty with slice of referenced array <lawshouse.public@btconnect.com>
    Re: Difficulty with slice of referenced array <do-not-use@invalid.net>
    Re: Difficulty with slice of referenced array <1usa@llenroc.ude.invalid>
    Re: Difficulty with slice of referenced array (Anno Siegel)
    Re: Difficulty with slice of referenced array <do-not-use@invalid.net>
        Looking to improve program (Tom Ewall)
    Re: matching all perldoc names but no more (Anno Siegel)
    Re: Reflection or discovery of object methods in perl? <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Nov 2004 11:35:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 'stat' and it's exceptions
Message-Id: <cmsueh$adt$1@mamenchi.zrz.TU-Berlin.DE>

fred  <fred@localhost.net> wrote in comp.lang.perl.misc:
> 
> 
> "So you are an honest freeloader?"
> 
> You bet! I later read on the advise of Michele and learned that {1,2}
> means match n things m times... so it gets both dots!
> 
> "Why no tell you to RTFM?" 
> 
> Becuase I *knew* the answer was in the docs! I just wanted to be spoon fed
> like a big baby!

That's what I figured.  I didn't bother to read the rest of your OP.
I suppose I'm not the only one...

Anno


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

Date: Wed, 10 Nov 2004 15:26:12 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 'stat' and it's exceptions
Message-Id: <pi74p05tet6j9l59uavc6qpfagp2p8v5o0@4ax.com>

On Tue, 09 Nov 2004 19:05:15 -0500, fred <fred@localhost.net> wrote:

>> But that's only a minor detail. However I'm under the impression that
>> the OP has got the script from some{one,where} else and is trying to
>> make sense of it...
>
>Actually, it's an original script I wrote. I did get a lot of help here
>just lurking.

Then MHO is that you've searched and *got* the wrong type of help. Of
course you may not be concerned at all by M(NS)HO, but stand warned:
your (alleged) learning method may bite you in the neck when you less
expect it...

>I enjoy CLPM but must confess I don't contribute any. I take a whole lot.
>On the other hand, I have been prgramming for a living 5 years... and I've
>been at perl for 6 months. So it's best I don't jump in often..

Why not? If you have something that *really* deserves asking (i.e.
being answered), you can ask it here.

>perl was real hard to pick up at first. Once I made sense of $_ it started
>betting easier.. at first this seemed incomprehensible: my(%times) = map
>{$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,readdir(DIR)) [snip]

This still looks incomprehensible... well, sort of. Certainly it can
be re-written in better, more clear, more maintainable ways. This is
not supposed to be a JAPH, after all, is it? If nothing else, fixing
whitespace/indenting would help a lot.

>Then you get to know that your loading a hash with a key and a value in a
>call to (1) stat and (2) grep and (3) readdir with the stat getting the
>file times as key and the grep avoiding the . and .. and the readdir
>geting you the filenames you wanted.

You know, it may just seem to you that I'm deliberately picky, but
what you wrote hardly makes any sense at all. The code, readability
issues apart, is much easier to understand than your description...

>>I don't understand this question: you are only statting the files that
>>match the pattern, if that's what you mean.

As a side note, when you quote, please make correct attributions. This
portion of text is quoted as many times as what I wrote, quoted above,
but I didn't write it.

>Yes eliminating .. and . -- that's everything! Then I have to
>backtrack and iterate again to get the matches I was looking for. Say I
>was really wanting only *.tmp but the pattern to be held in $pattern --
>the regex in the grep would have needed more muscle that I knew how to
>give it.

Ditto as above. Nay, to be fair I can't understand what you're
concerned about: do you have any issue with

  /$pattern/

by any chance?

>But I got it done. And you know that's subjective... Did "I" really get it
>done or did CLPM get it done... well CLPM did not write the script per
>se... or did it? It might be true to say: "Without CLPM you would have
[snip rest]

Out of curiosity: despite your resistance to read TFM, for which you
may think to have actual good motivations, haven't you even a
slightest doubt that it would have been more productive than writing
these 20 or so lines of rambling philo{soph,log}ical lucubrations
about "who wrote the script"?

Oh, and be sure that nobody will sue you for plagiarism re those two
lines of code. More realistically I guess that most regulars here
wouldn't want to be associated to them in any way...
;-)

>Thanks and I mean it.

You welcome and I mean it.


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: Wed, 10 Nov 2004 15:26:14 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 'stat' and it's exceptions
Message-Id: <5d84p09788lvgf2lqa8lfnbfvqgo1hg541@4ax.com>

On Tue, 09 Nov 2004 18:43:59 -0500, fred <fred@localhost.net> wrote:

>"Why no tell you to RTFM?" 
>
>Becuase I *knew* the answer was in the docs! I just wanted to be spoon fed
>like a big baby!

Just know that this is not generally accepted here: for once it can be
tolerated. If one adduces *good reasons* it can be tolerated too. But
no guarantee is given. OTOH insistence in this sense is likely to
raise flames. Be free to think that people here have an attitude, this
won't help you anyway: chances are you will be killfiled by those
whose help one may want to receive. Just to let you know...


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: 10 Nov 2004 12:12:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: [OT] Re: braindead languages?
Message-Id: <Xns959D49655FA7Dasu1cornelledu@132.236.56.8>

Michele Dondi <bik.mido@tiscalinet.it> wrote in 
news:h9k3p0hkdg1pfrobr6alp0isb4e2e5tbpo@4ax.com:

> On 9 Nov 2004 21:06:07 GMT, "A. Sinan Unur" <1usa@llenroc.ude.invalid>
> wrote:
> 
>>ITYM 
>>
>>perldoc perltoot | grep -A1 -B1 braindead 
>>
>>Usage: grep [OPTION]... PATTERN [FILE]...
> 
> Sorry to disagree with you and implicitly agree with the troll, but
> she's right: it will work the other way too, even though the usage
> line suggests differently. I don't know with more ancient
> implementations, but nowadays grep is often GNU grep, 

Thanks for the correction :)

For what it is worth, I had actually tried the OP's version using cygwin 
grep, and gotten

asu1@AardvarkIV ~
$ perldoc perltoot | grep 'braindead' -A 1 -B 1
grep: -A: No such file or directory
grep: 1: No such file or directory
grep: -B: No such file or directory
grep: 1: No such file or directory

Upon reading your post, I also tried on a Linux machine, and it worked. 
Good to know.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 10 Nov 2004 16:44:33 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmt64p$pvq$1@news.rol.ru>

thanks a lot for hint - unfortunately I've missed this module before.
Very good and handy job. I'm sure I'll use it in future, but
unfortunately, for my current task this module is not quite suitable :(
SO, the question is still remains actual.

Thanks, Andrew


Uri Guttman wrote:

> 
> use Event.pm instead. it is much better than IO::Select when you have
> many read/write sockets. if you use the OO callbacks, then you can
> associate an object with each socket and that object can tell the
> callback what to do.
> 
> uri

-- 
Andrew


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

Date: Wed, 10 Nov 2004 14:54:43 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmta39$5tb$1@gemini.csx.cam.ac.uk>

Andrew Tkachenko wrote:
> Hello.
> 
> Lets suppose I have a pool of about 300-400 non-blocking sockets and I want to
> monitor their state and do some actions depending on some events.

 From what I can see, your aim is to find out which element of @socks 
each socket you can read/write from is in. Am I right?

If so, I'd use Tie::RefHash (included in my distrib of 5.8, possibly not 
in older versions), which allows you to have hash references as keys. 
Then somewhere (probably where you set up @socks) create a RefHash with 
the sockets as keys and their array index as values. I think the 
following will work:

my %sock_index;
@sock_index{@socks}=(0..@socks);

but you'd better check that as I'm not certain I remember the syntax. 
Basically what I'm trying to do is something along the lines of

for(my $i=0;$i<@socks;$i++){
	$sock_index{$socks[$i]}=$i;
}

Then a modified version of your code would be:

while(1)
{
           my ($can_read, $can_write) = IO::Select->select($rd_set, 
$wr_set, undef, $TIMEOUT);
	
	  foreach my $reader(@$can_read){
		my $i = $sock_index{$reader};
		#read from socket
	  }
	  foreach my $writer(@$can_write){
		my $i = $sock_index{$writer};
		#write to socket
	  }

}

which avoids the massive loop through all of @socks. I'm assuming 
there's no reason to write/read in the order they are in @socks. If 
there is, then you can hopefully tweak mine to do what you want.


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

Date: Wed, 10 Nov 2004 15:53:21 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmtdh7$bhr$1@gemini.csx.cam.ac.uk>

Stuart Moore wrote:

Oops, missed a bit...

> 
> my %sock_index;

     tie %sock_index, 'Tie::RefHash';

> @sock_index{@socks}=(0..@socks);


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

Date: 10 Nov 2004 04:51:09 -0800
From: cs_hart@yahoo.com (Charlie)
Subject: Re: call pperl from c++ passing token list
Message-Id: <a94b517d.0411100451.4d2f3a8d@posting.google.com>

I was thinking of imbedding perl ( it had read that could be done) and
have the scripts (calculation routines) as external files so that they
could easily be replaced. I think my biggest problem is changing the
linked list of c++ tokens ( a class) that is passed to the calculation
routines, to a similar perl structure. From what I have read so far,
it appears an array of hash entries would be what I need. I've been
reading and plying with these, but if you have nay other suggestions
I'm open to other's experience.
charlie


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

Date: Wed, 10 Nov 2004 12:29:15 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Difficulty with slice of referenced array
Message-Id: <lu04p0df0bsrs7b92q4o727bk0fv4oi92c@4ax.com>

This doesn't seem to be a FAQ; I tried Googling but couldn't find a
suitable search string to get a manageable set of results ...

This is the core of my code:

#! /usr/bin/perl

use strict;
use warnings;

use Date::Calc qw(
   Date_to_Text
);

my @LoL;
push @LoL, [2001,12,25,"foo"];
push @LoL, [2004,4,6,"bar"];

# Gives expected output
foreach my $lref (@LoL) {
  print Date_to_Text($lref->[0],$lref->[1],$lref->[2]),"\n";
}

foreach my $lref (@LoL) {
  # Fails with message "Use of uninitialized value in range (or flip)"
  print Date_to_Text( $lref->[0..2] ), "\n";
}
__END__

I expected $lref->[0..2] to be a slice consisting of the first three
elements of the array pointed to by $lref, i.e. the same as
($lref->[0],$lref->[1],$lref->[2])) but plainly it's not.  In order to
get an array to pass to my subroutine am I condemned to coding the
elements separately, or is there a correct way of coding the slice?

Looking up flip-flops I can see that I've got some array-scalar
problem in the code, but I haven't been able to puzzle out what it is.
Can someone point me in the right direction?

Henry Law       <><     Manchester, England 


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

Date: 10 Nov 2004 12:57:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Difficulty with slice of referenced array
Message-Id: <cmt37q$ess$2@mamenchi.zrz.TU-Berlin.DE>

Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:
> This doesn't seem to be a FAQ; I tried Googling but couldn't find a
> suitable search string to get a manageable set of results ...
> 
> This is the core of my code:
> 
> #! /usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use Date::Calc qw(
>    Date_to_Text
> );
> 
> my @LoL;
> push @LoL, [2001,12,25,"foo"];
> push @LoL, [2004,4,6,"bar"];
> 
> # Gives expected output
> foreach my $lref (@LoL) {
>   print Date_to_Text($lref->[0],$lref->[1],$lref->[2]),"\n";
> }
> 
> foreach my $lref (@LoL) {
>   # Fails with message "Use of uninitialized value in range (or flip)"
>   print Date_to_Text( $lref->[0..2] ), "\n";
> }
> __END__
> 
> I expected $lref->[0..2] to be a slice consisting of the first three
> elements of the array pointed to by $lref, i.e. the same as
> ($lref->[0],$lref->[1],$lref->[2])) but plainly it's not.

Indeed it isn't.  $lref->[ ...] is always a scalar, In fact it's
syntactic sugar for ${ $lref}[ ...].

>                                                            In order to
> get an array to pass to my subroutine am I condemned to coding the
> elements separately, or is there a correct way of coding the slice?

There is.  What you want is the equivalent of @array[ 0 .. 2],
but with a ref to @array, not @array itself.  The rule is:  Replace
the name ("array") with a reference enclosed in {}.  So what you're
looking for is

    @{ $lref}[ 0 .. 2];

> Looking up flip-flops I can see that I've got some array-scalar
> problem in the code, but I haven't been able to puzzle out what it is.
> Can someone point me in the right direction?

That error message has come a long way.

In $lref->[ 0 .. 2], what is inside [] is in scalar context (since it
can't be a slice, there can only ever be one scalar in the []).  Now,
".." in scalar context has the (somewhat dubious) peculiarity that
it compares literal operands to $., the variable that holds the line
number from the last file read.  That means, it has assumed you had
written "$lref[ $. == 0 .. $. == 2].  Now, you're not reading a file,
so $. is undefined, and that is what it complains about.

Anno



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

Date: Wed, 10 Nov 2004 13:02:24 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Difficulty with slice of referenced array
Message-Id: <g344p0l5gmp882p29icohfkfchvbdmahbd@4ax.com>

On 10 Nov 2004 12:54:45 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:
 
>> foreach my $lref (@LoL) {
>>   # Fails with message "Use of uninitialized value in range (or flip)"
>>   print Date_to_Text( $lref->[0..2] ), "\n";

>That error message has come a long way.
>
>In $lref[ 0 .. 2], what is inside [] is in scalar context (since it
>can't be a slice, there can only ever be one scalar in the []).  Now,
>".." in scalar context has the (somewhat dubious) peculiarity that
>it compares literal operands to $., the variable that holds the line
>number from the last file read.  That means, it has assumed you had
>written "$lref[ $. == 0 .. $. == 2].  Now, you're not reading a file,
>so $. is undefined, and that is what it complains about.

Strewth ... it takes a Perl black belt to work that one out.  Thank
you for this wonderful explanation, and also for guidance on the
correct way to code a slice of a referenced array.  I'm going to
understand this stuff sooner or later, really I am.

Henry Law       <><     Manchester, England 


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

Date: 10 Nov 2004 14:34:43 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Difficulty with slice of referenced array
Message-Id: <yzdactpg74c.fsf@invalid.net>


anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:
> > This doesn't seem to be a FAQ; I tried Googling but couldn't find a
> > suitable search string to get a manageable set of results ...
> > 
> > This is the core of my code:
> > 
> > #! /usr/bin/perl
> > 
> > use strict;
> > use warnings;
> > 
> > use Date::Calc qw(
> >    Date_to_Text
> > );
> > 
> > my @LoL;
> > push @LoL, [2001,12,25,"foo"];
> > push @LoL, [2004,4,6,"bar"];
> > 
> > # Gives expected output
> > foreach my $lref (@LoL) {
> >   print Date_to_Text($lref->[0],$lref->[1],$lref->[2]),"\n";
> > }
> > 
> > foreach my $lref (@LoL) {
> >   # Fails with message "Use of uninitialized value in range (or flip)"
> >   print Date_to_Text( $lref->[0..2] ), "\n";
> > }
> > __END__
> > 
> > I expected $lref->[0..2] to be a slice consisting of the first three
> > elements of the array pointed to by $lref, i.e. the same as
> > ($lref->[0],$lref->[1],$lref->[2])) but plainly it's not.
> 
> Indeed it isn't.  $lref->[ ...] is always a scalar, In fact it's
> syntactic sugar for ${ $lref}[ ...].
> 
> >                                                            In order to
> > get an array to pass to my subroutine am I condemned to coding the
> > elements separately, or is there a correct way of coding the slice?
> 
> There is.  What you want is the equivalent of @array[ 0 .. 2],
> but with a ref to @array, not @array itself.  The rule is:  Replace
> the name ("array") with a reference enclosed in {}.  So what you're
> looking for is
> 
>     @{ $lref}[ 0 .. 2];
> 
> > Looking up flip-flops I can see that I've got some array-scalar
> > problem in the code, but I haven't been able to puzzle out what it is.
> > Can someone point me in the right direction?
> 
> That error message has come a long way.
> 
> In $lref[ 0 .. 2], what is inside [] is in scalar context (since it
> can't be a slice, there can only ever be one scalar in the []).  Now,
> ".." in scalar context has the (somewhat dubious) peculiarity that
> it compares literal operands to $., the variable that holds the line
> number from the last file read.  That means, it has assumed you had
> written "$lref[ $. == 0 .. $. == 2].  Now, you're not reading a file,
> so $. is undefined, and that is what it complains about.

I condensed the program to this while trying to understand what
happens. (The $i stuff was in order to have a loop without using any
 .. construct which might influence flip-flops.)  I don't understand
what happens when I have "use diagnostics" on:

#! /usr/bin/perl -w

use strict;
#use diagnostics;

my $lref = [1,2,3,4,5,6,7,8];

for (my $i = 0; $i < 6; $i++) {
    my $l2 = $lref->[0 .. 2];

    print "l2 = $l2\n";
}

This prints

Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1
Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1
Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1
Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1
Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1
Argument "" isn't numeric in aelem at ./bar2.pl line 10.
l2 = 1

as more or less expected from your explanation. But when I remove the
comment marker from the "use diagnostics" line, I get:

l2 = 2
l2 = 3
l2 = 4
l2 = 5
l2 = 6
l2 = 7

and no warnings. This I don't understand at all. (I'm on Perl 5.005,
in case it matters.)


Two minor questions, also:

1) Would it be bad style to write @$lref[0..2] rather than
@{$lref}[0..2]?

2) To help the original poster, would it be correct to say that
something beginning with '$' produces a scalar, and something
beginning with '@' produces a list or array? This principle would show
that $lref->[0..2] can't be an array slice. (But it wouldn't help
explain why @lref->[0..2] isn't the solution, of course...)



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

Date: 10 Nov 2004 14:07:14 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Difficulty with slice of referenced array
Message-Id: <Xns959D5CC817DA1asu1cornelledu@132.236.56.8>

Arndt Jonasson <do-not-use@invalid.net> wrote in 
news:yzdactpg74c.fsf@invalid.net:

> I condensed the program to this while trying to understand what
> happens. (The $i stuff was in order to have a loop without using any
> .. construct which might influence flip-flops.)  I don't understand
> what happens when I have "use diagnostics" on:

That I don't understand either.

However ...

> #! /usr/bin/perl -w
> 
> use strict;
> #use diagnostics;
> 
> my $lref = [1,2,3,4,5,6,7,8];

$lref is not a reference to a list. It is a reference to an anonymous 
array. Hence, the first letter is a little misleading, esp in light of 
your later comment.
 
> Two minor questions, also:
> 
> 1) Would it be bad style to write @$lref[0..2] rather than
> @{$lref}[0..2]?

Depends on context.
 
> 2) To help the original poster, would it be correct to say that
> something beginning with '$' produces a scalar, and something
> beginning with '@' produces a list or array?

perldoc -q list

Sinan.



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

Date: 10 Nov 2004 14:19:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Difficulty with slice of referenced array
Message-Id: <cmt813$idl$1@mamenchi.zrz.TU-Berlin.DE>

Arndt Jonasson  <do-not-use@invalid.net> wrote in comp.lang.perl.misc:

> I condensed the program to this while trying to understand what
> happens. (The $i stuff was in order to have a loop without using any
> .. construct which might influence flip-flops.)  I don't understand
> what happens when I have "use diagnostics" on:
> 
> #! /usr/bin/perl -w
> 
> use strict;
> #use diagnostics;
> 
> my $lref = [1,2,3,4,5,6,7,8];
> 
> for (my $i = 0; $i < 6; $i++) {
>     my $l2 = $lref->[0 .. 2];
> 
>     print "l2 = $l2\n";
> }
> 
> This prints
> 
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> Argument "" isn't numeric in aelem at ./bar2.pl line 10.
> l2 = 1
> 
> as more or less expected from your explanation. But when I remove the
> comment marker from the "use diagnostics" line, I get:
> 
> l2 = 2
> l2 = 3
> l2 = 4
> l2 = 5
> l2 = 6
> l2 = 7
> 
> and no warnings. This I don't understand at all. (I'm on Perl 5.005,
> in case it matters.)

diagnostics.pm reads a file during its initialization.  As a side
effect, after "use diagnostics", $. has a defined value (of 0) instead
of undef without it.  That allows "0 .. 2" to start off its sequence
(1, 2, 3...) of true values (read about it in perlop) which never
ends because the right operand "$. == 2" never becomes true.  That
gives you the values $lref->[ 1], $lref->[ 2], ... you're seeing.

> Two minor questions, also:
> 
> 1) Would it be bad style to write @$lref[0..2] rather than
> @{$lref}[0..2]?

It's possible, but the precedence rules that allow you to leave
out the {} are pretty obscure.  Except for the most simple cases
I would recommend to leave them in.

> 2) To help the original poster, would it be correct to say that
> something beginning with '$' produces a scalar, and something
> beginning with '@' produces a list or array? This principle would show
> that $lref->[0..2] can't be an array slice. (But it wouldn't help
> explain why @lref->[0..2] isn't the solution, of course...)

 ...nor is the rule "if it begins with $, it's a scalar" without
exceptions.  Think of "$x = sub { 1, 2, 3 }; @y = $x->();".  So
I prefer not to quote that rule, it only leads to more discussion... :)

Anno


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

Date: 10 Nov 2004 15:34:55 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Difficulty with slice of referenced array
Message-Id: <yzd4qjxg4c0.fsf@invalid.net>


"A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
> Arndt Jonasson <do-not-use@invalid.net> wrote in 
> news:yzdactpg74c.fsf@invalid.net:
> > my $lref = [1,2,3,4,5,6,7,8];
> 
> $lref is not a reference to a list. It is a reference to an anonymous 
> array. Hence, the first letter is a little misleading, esp in light of 
> your later comment.

Sorry about that, but I kept the name "lref" from the original question.


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

Date: 10 Nov 2004 08:02:15 -0800
From: tewall@lycos.com (Tom Ewall)
Subject: Looking to improve program
Message-Id: <85bf428.0411100802.1d234182@posting.google.com>

The following code looks for files in a directory with lables of "Run
A" "Run B" "Run C" or "Run D".  Each of the files has a total line. 
It grabs the total, something like "$211,153" and strips out the "$"
and the ",".

The program works, but I'm sure there are more efficient/perl
idiomatic ways of doing things than how I've done them here.  I'm
looking for suggested improvements.
-----------------------------------------------------------------------


#!\Perl\bin\perl

use strict;

my $total;
my @total;
my $runA;
my $runB;
my $runC;
my $runD;
my @list;
my $lmoDir = "/__lmo";


opendir(LMODIR, $lmoDir) or die "could not open LMO directory";
my @allfiles = grep !/^\.\.?\z/, readdir LMODIR; # exclude . and ..
files
closedir(LMODIR);

foreach my $file (@allfiles){
    open LMO, "$lmoDir/$file" or die "Cannot open file: $!";
    my @list=<LMO>;   
    foreach (@list) {
        if (/Run/){
            $run = "$_";
            chomp ($run);
        }                                
        if (/Total/){
            $total = "$_";
            chomp ($total);
        }    
    }    
    @total = split(/\t/, $total);       
    $total = @total[$#total - 2];
    if ($run eq 'Run A'){        
        $runA = $total;
    }    
    if ($run eq 'Run B'){        
        $runB = $total;
    }    
    if ($run eq 'Run C'){        
        $runC = $total;
    }    
    if ($run eq 'Run D'){        
        $runD = $total;
    }        
}

$_ = $runA;
s/,//;
s/\$//;
$runA = $_;

$_ = $runB;
s/,//;
s/\$//;
$runB = $_;

$_ = $runC;
s/,//;
s/\$//;
$runC = $_;

$_ = $runD;
s/,//;
s/\$//;
$runD = $_;


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

Date: 10 Nov 2004 12:12:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: matching all perldoc names but no more
Message-Id: <cmt0ii$adt$2@mamenchi.zrz.TU-Berlin.DE>

Alan J. Flavell <flavell@ph.gla.ac.uk> wrote in comp.lang.perl.misc:
> On Tue, 9 Nov 2004, Ben Morrow wrote:

> > The locale is externally-derived data. A malicious user could (under
> > some OSen at least) construct their own locale that said ';' was a word
> > character.
> 
> Good call.  I withdraw the comment.
> 
> > I would hope (but I haven't tested) that if 'use locale' is in effect
> > and the locale setting was tainted then such regexen won't untaint...
> 
> Let's hope so.

I don't find it in the documentation, but a test shows that a regex
that is itself tainted (i.e. interpolates a tainted string) doesn't
launder tainted data.

Anno


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

Date: Wed, 10 Nov 2004 15:26:15 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <c794p0h25m8kpmf1o2i7dcsph1vh5p8heq@4ax.com>

On 9 Nov 2004 23:11:47 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>"defined &foo" is special, it tests if a sub is defined (has code
>associated with it).  It's the standard way of testing if a sub

My fault, I plainly didn't know! Yet another bit of magic, I see...
incidentally this may be yet another good reason not to use the &-form
of sub call. E.g.:

  my $def;
  defined &{$_} and $def++ for \&sub1, \&sub2, \&sub3;

will always give me $def==3, IIUC.

>> Also, were I doing this for a generic package, say $pkg, rather than
>> main, should I use something like
>> 
>>   *{"${pkg}::$_"}{CODE}
>
>Well... it works.
[snip rest]

TY for your helpful cmts.


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 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 7388
***************************************


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