-
1
- #1
I wrote a small piece of codes to test out ReadOnly.pm.
And below is the output:
Question:
1) Why do I get this "Modification of a read-only value attempted" error?
2) Why doesn't the same error show at Line 24?
I don't see any difference between line 24 and line 31.
Thanks for the help.
Code:
use Readonly;
Readonly::Hash my %readOnlyHash1 => (
'key11'=>{
'key21'=>1,
'key22'=>1,
},
'xyz'=>{
'abc'=>1,
},
);
Readonly::Hash my %readOnlyHash2 => (
'xyz'=>{
'abc'=>1,
},
);
my $k1 = 'key11';
my $k2 = 'key31';
if(defined($readOnlyHash1{$k1}{$k2})) { [b]# line 24[/b]
print "Defined: Key 1 - $k1, Key 2 - $k2\n";
}
else {
print "Not Defined: Key 1 - $k1, Key 2 - $k2\n";
}
if(defined($readOnlyHash2{$k1}{$k2})) { [b]# line 31[/b]
print "Defined: Key 1 - $k1, Key 2 - $k2\n";
}
else {
print "Not Defined: Key 1 - $k1, Key 2 - $k2\n";
}
And below is the output:
Code:
% test.pl
Not Defined: Key 1 - key11, Key 2 - key31
Modification of a read-only value attempted at ./test.pl line 31
Question:
1) Why do I get this "Modification of a read-only value attempted" error?
2) Why doesn't the same error show at Line 24?
I don't see any difference between line 24 and line 31.
Thanks for the help.