Hello
I am new to perl and learning ...can you please explain why am i getting this error...as myHash is defined right above the code and I think it should be avilable in the sub function.
Here is my code:
#!/usr/bin/perl
use warnings;
use strict;
%myHash=();
sub populateHash
{
my $MY_FILE="file.properties";
open my $PFILE, '<', $MY_FILE or die "Cannot open '$MY_FILE' $!";
LINE: while (<$PFILE>)
{
# now read the line and remove all white spaces, tab and new line char
+s or any trailing spaces
$_ =~ s/\s+$//;
next LINE if (/^\s*#/); # ignore commented lines
next LINE if (/^$/); # ignore null lines
my $n=substr($_,0,index($_,'='));
my $v=substr($_,index($_,'=')+1);
$myHash->{$n}=$v;
}
close $PFILE;
}
&populateHash();
while ( my ($key, $value) = each(%myHash) ) {
print "From myHash --> $key => $value\n";
}
I get the below error:
Global symbol "%envPropertiesHash" requires explicit package name at f
+irst.pl line 5.
Global symbol "$envPropertiesHash" requires explicit package name at f
+irst.pl line 22.
Global symbol "%envPropertiesHash" requires explicit package name at f
+irst.pl line 31.
Execution of first.pl aborted due to compilation errors.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.