Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

by 2teez (Vicar)
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-06-21 03:44 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.