Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: How to goto new sub if file empty?

by pfaut (Priest)
on Apr 23, 2003 at 05:25 UTC ( #252454=note: print w/replies, xml ) Need Help??

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!!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2021-03-04 22:12 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (108 votes). Check out past polls.