I am trying to save log messages in a hash depending on the type of message, as shown below:
#!/usr/bin/perl use strict; use warnings; my %log; opendir (DIR, '.') or die $!; while (my $file = readdir(DIR)) {
Now this code gives a compilation error:
Global symbol "$log" requires explicit package name at at lines 12 & 16
where I'm really trying to use the hash "% log". What could be a possible way to get rid of this error? Why is this exactly happening?
I saw some explanations in a context where people answered that the variables were created in one context and passed in another, but I believe that this variable should be available inside the while loop in this piece of code. This only happens when I βuse strictβ and works fine otherwise.
I started with Perl, so I do not fully understand the basics! Please help me understand why this variable is not available.
source share