diff options
author | Ricardo Signes <rjbs@cpan.org> | 2013-09-26 22:44:00 -0400 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2013-10-05 14:20:10 -0400 |
commit | 821361b63ca5bf477eebc88759d8f3e7f69a93e3 (patch) | |
tree | 6e7ee1667fa399f9fe00fa5ac50944e78ea09f9c /pod/perlref.pod | |
parent | 760ca74635309e90553eeb15e5ac62e6f19f5d86 (diff) | |
download | perl-821361b63ca5bf477eebc88759d8f3e7f69a93e3.tar.gz |
preliminary postfix dereference docs
This commit adds an overview of the feature to perlref and a pointer
to the section in perlref to perlop's documentation of the arrow.
If/when this feature becomes non-experimental, the documentation
should be merged upward into Using References.
This documentation was written against a previous state of the
branch. Is should be fact-checked before any merge.
Diffstat (limited to 'pod/perlref.pod')
-rw-r--r-- | pod/perlref.pod | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pod/perlref.pod b/pod/perlref.pod index 4ed7e95780..e9f7974c6f 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -744,6 +744,60 @@ real refs, instead of the keys(), which won't. The standard Tie::RefHash module provides a convenient workaround to this. +=head1 Postfix Dereference Syntax + +Beginning in v5.20.0, a postfix syntax for using references is +available. It behaves as described in L</Using References>, but instead +of a prefixed sigil, a postfixed sigil-and-star is used. + +For example: + + $r = \@a; + @b = $r->@*; # equivalent to @$r or @{ $r } + + $r = [ 1, [ 2, 3 ], 4 ]; + $r->[1]->@*; # equivalent to @{ $r->[1] } + +This syntax must be enabled with C<use feature 'postderef'>. It is +experimental, and will warn by default unless C<no warnings +'experimental::postderef'> is in effect. + +Postfix dereference should work in all circumstances where block +(circumfix) dereference worked, and should be entirely equivalent. This +syntax allows dereferencing to be written and read entirely +left-to-right. The following equivalencies are defined: + + $sref->$*; # same as ${ $sref } + $aref->@*; # same as @{ $aref } + $href->%*; # same as %{ $href } + $cref->&*; # same as &{ $cref } + +Note especially that C<< $cref->&* >> is I<not> equivalent to C<< +$cref->() >>, and can serve different purposes. C<< $gref->** >> is not +(yet?) implemented. + +Postfix array and scalar dereferencing I<can> be used in interpolating +strings (double quotes or the C<qq> operator), but only if the +additional C<postderef_qq> feature is enabled. + +=head2 Postfix Reference Slicing + +Value slices of arrays and hashes may also be taken with postfix +dereferencing notation, with the following equivalencies: + + $aref->@[ ... ]; # same as @$aref[ ... ] + $href->@{ ... }; # same as @$href{ ... } + +Postfix key/value pair slicing is not I<yet> implemented, but will +behave as expected: + + $aref->%[ ... ]; # same as %$aref[ ... ] + $href->%{ ... }; # same as %$href{ ... } + +As with postfix array, postfix value slice dereferencing I<can> be used +in interpolating strings (double quotes or the C<qq> operator), but only +if the additional C<postderef_qq> feature is enabled. + =head1 SEE ALSO Besides the obvious documents, source code can be instructive. |