R. Joseph Newton wrote:
> Rob Dixon wrote:
>
> > push @line, scalar <DATA> for 1..3;
>
> So the scalar function is creating an anonymous scalar for insertion into @line?
No, it's just forcing scalar context onto the <> operator. The 'push' function
takes a list as its second parameter so it would otherwise be in list context.
The entire file would be read and pushed onto the array in the first loop
execution, then 'undef' would be pushed twice as the file was at eof.
<> in scalar context reads just one record from the filehandle, which is
what we want.
Another way to do this is to append the null string (for textual data, as here)
or add zero (for numeric data). I just felt like using 'scalar' this time! The
following works because the concatenation operator has a higher priority
than the comma list operator, so putting the <> into scalar context.
push @line, <DATA> . "" for 1..3;
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]