Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Need help with script with a while loop reading file

by 2teez (Priest)
on May 03, 2013 at 16:23 UTC ( #1031924=note: print w/replies, xml ) Need Help??

in reply to Need help with script with a while loop reading file

Hi brianjb,
I know your question has been probably answered :).
However, if I may draw your attention to some stuff in your code:

  • this
    open FILE, "<hostname_check.txt" || die $!;
    would fail to do what you intended, in case your file doesn't exists.
    It's better written as
    open ( FILE, "<hostname_check.txt" ) || die $!;
    open FILE, "<hostname_check.txt" or die $!;
  • Use lexically scoped filehanles and the 3-argument open function like so:
    open my $fh, '<',"hostname_check.txt" or die $!;
  • Also check the return of close function

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2016-10-23 01:39 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (299 votes). Check out past polls.