runrig has asked for the wisdom of the Perl Monks concerning the following question:
I'm wondering about the behaviour of the following:
This prints (on perl 5.14.1):use Scalar::Util qw(readonly);; my %hash = ( A => 1 ); while ( my ( $abc, $num ) = each %hash ) { print "$abc\n"; print "$abc is readonly\n" if readonly($abc); my $bar = $abc; print "bar is readonly\n" if readonly($bar); foo($abc); print "$abc is still readonly\n" if readonly($abc); } sub foo { $_[0] .= 'FOO'; }
First, I don't expect $abc to be read-only, as it is not an alias for the hash key, but if it is readonly, then the call to foo() should not work, we should get a "modification of a readonly value" error. And why is $bar read-only? It's just a copy of the value in $abc. Or has this changed in recent versions of perl?A A is readonly bar is readonly
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Readonly problems (Devel::Peek, Scalar::Util::readonly bug)
by Anonymous Monk on Dec 17, 2013 at 01:21 UTC | |
by Anonymous Monk on Dec 17, 2013 at 01:35 UTC | |
by runrig (Abbot) on Dec 17, 2013 at 01:47 UTC | |
by choroba (Cardinal) on Dec 17, 2013 at 14:53 UTC | |
by runrig (Abbot) on Dec 17, 2013 at 16:47 UTC | |
|
Back to
Seekers of Perl Wisdom