Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to goto new sub if file empty?

by pfaut (Priest)
on Apr 23, 2003 at 05:25 UTC ( [id://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.
dragonchild

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found