http://www.perlmonks.org?node_id=1016461


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

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".