in reply to Re: Grepping the filehandler
in thread Grepping the filehandler

Thanks for your explanation.

I tried to reference the file handler with a readline which gave the last line when it is dereferenced. Bit confused here as in the previously mentioned code it considers the first line of a file in a scalar context but when it comes to referencing last line is considered.

open $f,'<','file' or die $!; my $r=\<$f>; print ref($f);#SCALAR print "$$r";# prints the last line of the code

Replies are listed 'Best First'.
Re^3: Grepping the filehandler
by haukex (Archbishop) on Jul 23, 2020 at 17:39 UTC

    The \ operator in this case "puts its operand in list context, and creates a list of references to the scalars in the list provided by the operand", so the readline is in list context here and reading all the lines from the file. So in other words it's the same as my $r = \("Line1","Line2","...","LineN");, and a list in scalar context returns its last element.