> Actually, I have no idea what the semantics of <> are. I don't even know what > you call that syntactically - anonymous filehandle constant? Can you point me > to documentation about the semantics of that thing?
Its a special case of a <filehandle>. perldoc perlop If a <FILEHANDLE> is used in a context that is looking for a list, a list comprising all input lines is returned, one line per list element. It's easy to grow to a rather large data space this way, so use with care. <FILEHANDLE> may also be spelled readline(*FILEHANDLE). See readline. The null filehandle <> is special: it can be used to emulate the behavior of sed and awk. Input from <> comes either from standard input, or from each file listed on the command line. Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames. The loop 1. while (<>) { 2. ... # code for each line 3. } is equivalent to the following Perl-like pseudo code: 1. unshift(@ARGV, '-') unless @ARGV; 2. while ($ARGV = shift) { 3. open(ARGV, $ARGV); 4. while (<ARGV>) { 5. ... # code for each line 6. } 7. } except that it isn't so cumbersome to say, and will actually work. It really does shift the @ARGV array and put the current filename into the $ARGV variable. It also uses filehandle ARGV internally--<> is just a synonym for <ARGV>, which is magical. (The pseudo code above doesn't work because it treats <ARGV> as non-magical.) There is more. -- Please post to: Hampshire@mailman.lug.org.uk Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire LUG URL: http://www.hantslug.org.uk --------------------------------------------------------------