In Perl, why can't I bless a variable which contains a reference to a literal?

Viewed 496

I've been trying to learn Perl for a few days, and am still frequently surprised and sometimes mystified at how and why it does things. Here is my latest puzzle: why are the following two blocks of code not equivalent?

my $thing = '';
bless \$thing; # class is implicit

versus

my $thing = \'';
bless $thing; # class again implicit

The second form says "Modification of a read-only value attempted" on the second line.

2 Answers
Related