Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Your favourite gory detail...

by ihb (Deacon)
on Jun 21, 2004 at 19:26 UTC ( #368536=note: print w/replies, xml ) Need Help??

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!


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?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://368536]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-10-24 16:43 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.