Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?

by 7stud (Deacon)
on Feb 01, 2013 at 06:07 UTC ( #1016455=note: print w/ replies, xml ) Need Help??


in reply to Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?

This doesn't produce an error:

my $fname = 'data.txt'; open FH, "<", $fname or die "Couldn't open $fname: $!"; while(FH) { print "hello\n"; }
Nor does this:
while(FH) { print "hello\n"; }

According to "Perl Best Practices", p. 65:

In Perl, any identifier that the compiler doesn't recognize as a subroutine (or as package name or filehandle or label or builtin function) is treated as an unquoted character string:

$greeting = Hello . World; print $greeting, "\n"; #Prints: HelloWorld
I'm not sure why there are parentheses around "or package name or filehandle..." because the section is not about subroutines. And it should say, "...is treated as a string".


Comment on Re: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?
Select or Download Code
Re^2: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?
by parv (Priest) on Feb 01, 2013 at 06:45 UTC

    You missed to read the error message in OP, repeated below for you, that has the clue ...

    user@localhost ~$ ./strip_keys.pl -u user my-device.config Bareword "KNOWN_HOSTS" not allowed while "strict subs" in use at ./str +ip_keys.pl line 92. Execution of ./strip_keys.pl aborted due to compilation errors.

    ... run your own 1st snippet of code with "use strict;" and be able to reproduce the fatal error similar to above. Also, read up on "constant" pragma and "bareword".

      No, I saw it eventually--I was still editing my post when you posted. :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-10-25 23:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls