Created
December 26, 2020 16:39
-
-
Save arunbear/12d830f422650c7151652c359d5d2805 to your computer and use it in GitHub Desktop.
lvalue methods in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pirl @> sub hats : lvalue { my ($self) = @_; $self->{hats}; } | |
@var = (); | |
pirl @> $obj = bless {} | |
@var = ( | |
bless( {}, 'Shell::Perl::sandbox' ) | |
); | |
pirl @> $obj->hats | |
@var = ( | |
undef | |
); | |
pirl @> $obj | |
@var = ( | |
bless( {}, 'Shell::Perl::sandbox' ) | |
); | |
pirl @> $obj->hats = 1 | |
@var = ( | |
1 | |
); | |
pirl @> $obj | |
@var = ( | |
bless( { | |
'hats' => 1 | |
}, 'Shell::Perl::sandbox' ) | |
); | |
pirl @> $obj->hats | |
@var = ( | |
1 | |
); | |
pirl @> $obj->hats++ | |
@var = ( | |
1 | |
); | |
pirl @> $obj->hats | |
@var = ( | |
2 | |
); | |
pirl @> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment