Today’s bit of black perl

use 5.010;
{
   
package F;
   
sub new { bless {}, shift }
   
sub me { $_[0] = 'surprise!' }
}
my $f = F->new;
say $f
;
$f
->me;
say $f
;

Output:

F=HASH(0x7f9daa025c80)
surprise!

Teehee…

2 Comments

That's know forever. Changing @_ elements directly is destructive. shift @_ creates a copy. With methods destroying $self (i.e. $_[0]) is of course evil.

Leave a comment

Sign in to comment, or comment anonymously.

About Aristotle

user-pic Waxing philosophical