Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

DAxelrod (4649)

  (email not shown publicly)

I'm interested in hard problems.

Recently, I've started thinking a lot about what CP6AN might look like.

Class::MOP and the Perl 6 Metamodel make me more excited than I'd like to admit.

Also expect occasional wordy technology-related rantings.

Journal of DAxelrod (4649)

Wednesday November 01, 2006
03:38 PM

When read-only isn't

[ #31476 ]

Step up, one and all, and see me modify a simple scalar only by reading it. Nothing up my sleeves.

my ($num, $let, $foo);
$num = "z";
$let = $num;
#$foo = 1 + $num; #this does not modify $num
$num++; $let++;
print "num:$num let:$let\n";
num:aa let:aa

Output with 1+$num line uncommented:
num:1 let:aa

This means we have a line that makes no assignment to a variable, but still changes that variable.

Critics will call this dangerous and unexpected action at a distance. Proponents will note that a warning is triggered, read-only statements are still an indication of What You Mean, and that this probably makes excellent fodder for obfus.

Admittedly, this is (sorta) documented. Perlop mentions "If, however, the variable has been used in only string contexts since it was set," the ++ operator acts differently.

Abigail's comment to this discussion about side effects inspired this experiment^W magic trick.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.