http://www.perlmonks.org?node_id=368536


in reply to Your favourite gory detail...

This isn't exactly a favourite... The fact that there's a difference between ref and ref() is... well, it simply scares me. :-) It's almost like your example, a seemlingly innocent parethesis makes a huge difference, except the behaviour in your example makes sense and is consistent.

An eof without an argument uses the last file read. Using eof() with empty parentheses is very different. It refers to the pseudo file formed from the files listed on the command line and accessed via the <> operator.

So far it doesn't seem that evil. But wait, it goes on...

Since <> isn't explicitly opened, as a normal filehandle is, an eof() before <> has been used will cause @ARGV to be examined to determine if input is available. Similarly, an eof() after <> has returned end-of-file will assume you are processing another @ARGV list, and if you haven't set @ARGV, will read input from STDIN;

That's just too much magic for one parenthesis!

ihb

Replies are listed 'Best First'.
Re^2: Your favourite gory detail...
by ysth (Canon) on Jun 23, 2004 at 06:18 UTC
    It does even more if you are using the -i flag.

    Update: to be more explicit, under -i, a simple eof() will (if needed) pull the next file(s) off of @ARGV, renaming and creating a new file for each until it gets to a non-empty one, and then selects that one as the default output file:

    $ rm foo{.bak,};echo bar>foo;perl -i.bak -we'sub show { print STDOUT " +files: ", join(",", glob("*")), "\nselected: $_\n" and select $_ for select *{" +TEMP"} } show; print STDOUT eof() ? "eof\n" : "not eof\n"; show' foo files: foo selected: main::STDOUT not eof files: foo,foo.bak selected: main::ARGVOUT
Re^2: Your favourite gory detail...
by bunnyman (Hermit) on Jun 22, 2004 at 18:17 UTC
    The fact that there's a difference between ref and ref() is... well, it simply scares me. :-)

    Like what?