#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Scalar::Readonly ':all';
my $count = 0;
my @savearr = ();
eval {
sub make {
save('begin '.$count++.' end');
}
sub save {
readonly_on($_[0]); #comment this out
push(@savearr, \$_[0]);
}
for(0..3) {
make();
}
print(Dumper(\@savearr));
};
if($@) {
print("failed in eval with\n\"$@\"\n".Dumper(\@savearr));
}
####
C:\Documents and Settings\Owner\Desktop>perl ro.pl
failed in eval with
"Modification of a read-only value attempted at ro.pl line 9.
"
$VAR1 = [
\"begin 0 end"
];
C:\Documents and Settings\Owner\Desktop>
####
C:\Documents and Settings\Owner\Desktop>perl ro.pl
$VAR1 = [
\"begin 0 end",
\"begin 1 end",
\"begin 2 end",
\"begin 3 end"
];
C:\Documents and Settings\Owner\Desktop>