in reply to How to goto new sub if file empty?

If the file is empty, the first attempt to read from it returns false (undef) and you never execute the body of the while loop. Your call of &stopit is inside that body so it never gets called. You can check for an empty file with eof before executing the while.

open(FILE, "links.dat") || die "Can't open file!"; flock(FILE, 2) || die "Can't lock file!"; stopit if eof FILE; while ($line = <FILE>) { ....
90% of every Perl application is already written.

Replies are listed 'Best First'.
Re: Re: How to goto new sub if file empty?
by Anonymous Monk on Apr 23, 2003 at 05:39 UTC
    Thanks a million pfaut!

    That was exactlly what I was trying to figure out... how to check for content in the file before I assigned it to a variable and started a loop :)

    Thanks again!!