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


in reply to Global symbol .... requires explicit package name at

use diagnostics

Global symbol "$files" requires explicit package name at 1.pl line 19. Execution of 1.pl aborted due to compilation errors (#1) (F) You've said "use strict" or "use strict vars", which indicates + that all variables must either be lexically scoped (using "my" or +"state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").

The variable $files isn't lexical. foreach (and for) uses $_ by default, but if you specify a variable name before the list, it's roughly equivalent to

foreach (@files) { $files = $_; #etc...

So to be properly strict, you need to use my. Here are some examples of odd places where you would have to use my:

for my $i ( 0 .. 10 ) { print "$i\n" } open my $fh, '<', "/etc/passwd"; while (my $line = <>) { next if /^\s*#/ }
print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))