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

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 $!;
    or
    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


Comment on Re: Need help with script with a while loop reading file
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2015-08-01 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls