Why does line 18 required explicit package name in the code below?
#! /usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw<say state>;
{
no strict;
no warnings;
$myRef{G4143} = 58;
$myRef{Emily} = 8;
$myRef{Angela} = 40;
}
#%myRef requires explicit package name
while (my ($key, $value) = each %myRef) {
say "$key=>$value";
}
exit(0);
If I add the main package to %myRef on line 18, then it works
#! /usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw<say state>;
{
no strict;
no warnings;
$myRef{G4143} = 58;
$myRef{Emily} = 8;
$myRef{Angela} = 40;
}
#added package name and now it works
while (my ($key, $value) = each %main::myRef) {
say "$key=>$value";
}
exit(0);
Why is the package name required in this example?