Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Good Day, When using the follwing code, you can process a number of files sequencially.
use strict; use warnings; while (<>) { print $_; }
Question: How do you find out when one file has completed and your about to get the next file's data? Regards, Mark P Ashworth

Replies are listed 'Best First'.
Re: Determining new file
by nite_man (Deacon) on Mar 28, 2003 at 07:35 UTC
    Use function eof:
    eof(); # Return 1 for EOF for last file in your list eof; # Return 1 for EOF for each file from your list
    It's 'magic' property of this function.
    --------> SV* sv_bless(SV* sv, HV* stash);
Re: Determining new file
by robartes (Priest) on Mar 28, 2003 at 07:44 UTC
    Another way of doing this (hey, this is TIMTOWTDIMonks after all) is to make use of the fact that $ARGV gets set to the current file:
    my $file; while(<>) { print "Changing file to: $file\n" if ( qq/$file/ ne ( $file=$ARGV)); print; }

    CU
    Robartes-

Re: Determining new file
by Paladin (Vicar) on Mar 28, 2003 at 07:34 UTC
    You can use eof to check for end of file. There is an example similar to what you want in the perldoc for eof. Something like:
    # insert dashes just before last line of last file while (<>) { # Do stuff with each line if (eof) { # check for end of current file print "I am at the end of the file\n"; close(ARGV); # close or last; is needed if we # are reading from the terminal } }
    Update: Corrected eof() to eof
      Use eof without parentheses to test for end of each individual file in ARGV.