[kw-pm] is perl 6 really that different?

Robert P. J. Day rpjday at mindspring.com
Tue Jul 8 19:19:29 CDT 2003


On Tue, 8 Jul 2003, Simon Law wrote:

> On Tue, Jul 08, 2003 at 06:58:39PM -0400, Robert P. J. Day wrote:
 
> >   $arr[0] = FH ;
> >   @arr[0] = FH ;
> 
> 	The second does not seem semantically correct for Perl 5.
> Especially if you've already declared 
> 
> my @arr;
> 
> earlier in the program.  (Otherwise, the first line would not make
> sense.)

but the "gotcha" above is a well-known feature of perl 5 that is used
to emphasize why you shouldn't confuse those two syntaxes.

an open filehandle in an array context returns the entire remaining
contents of the file as a list, one line per list entry.  if you use
that second form, the array context forces just that, while only having
room to store the first of all those lines.  all the rest are read and
discarded.

really.  i'm not making this up.  i've seen this example in at
least two different places as an example of what can go wrong
if you confuse the proper way to refer to an array element in 
perl 5.

has no one else ever seen this?

rday




More information about the kw-pm mailing list