[EMAIL PROTECTED] (Leon) writes:

> >   open FILE, "filename" or die $!;
> >   my $line = <FILE>;
> >   close FILE;
> >
> > Remember, <FILEHANDLE> is something you can iterate over.  In scalar
> > context it returns just one line (for all intents and purposes) at a
> > time.
> 
> Am I right to say that although $line reads the first line, the whole file
> is still being read till the end of file.


No.  In a scalar context it reads the following line.  Lines
after that one are *not* read and are available for
subsequent reading.  That's why it can be used in a loop.
If it read everything the first time, there would be no
second time.

> If I am sitting for a test, I failed because I would probably think that
> $line = <FILE> would read the last line, I say so because of the following
> reasons:-

You psyched yourself out -- brain loop....



> my @line =<FILEHANDLE>; reads every line into @line, 

The reason this reads the last line is because it reads
every line.  There's nothing special about the last line
except that it's part of "all the rest".  The thing that
tripped this behavior is list context.

This is in _list_ context.
> my @line =<FILEHANDLE>;

The original code was in _scalar_ context.
> >   my $line = <FILE>;

-- 
Michael R. Wolf
    All mammals learn by playing!
        [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to