in reply to diamond operator

You can nearly do this with just <> and without touching @ARGV. First read eof then consider:

while( <> ) { print "First: $_"; last if eof; # Stop at end of /first/ file } while( <> ) { print; }

But this actually does special processing of the first non-empty file, not the first file. Detecting that the first file is non-empty without directly modifying @ARGV is trickier:

my $args= @ARGV; if( ! eof() # Prime the <> pump && @ARGV == $args-1 # Did we not move past the first file? ) { while( <> ) { print "First: $_"; last if eof; } } while( <> ) { print; }

In any case, I find it an interesting solution.

(Updated within seconds of posting to replace a near solution with a real solution.)

- tye        

Replies are listed 'Best First'.
Re^2: diamond operator (eof)
by Anonymous Monk on Jun 09, 2009 at 14:59 UTC
    sweet, this first exemple looks quite clean, now I have to choose between poping the @ARGV or an extra if, although my C mind says "no useless if's" I guess I'll use it.