X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsub.pod;h=325c823bff4107e99d2896a63a481769ce9407bf;hb=197afce1e759b5f0a1885a151064a83b27a7324e;hp=74d0b1ac26fed091d13a05a0fbfd40c241606d29;hpb=803e1be1305f7c1b058f40840ab0d19e2d92a3d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsub.pod b/pod/perlsub.pod index 74d0b1a..325c823 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -535,6 +535,7 @@ Synopsis: local @oof = @bar; # make @oof dynamic, and init it local $hash{key} = "val"; # sets a local value for this hash entry + delete local $hash{key}; # delete this entry for the current block local ($cond ? $v1 : $v2); # several types of lvalues support # localization @@ -692,6 +693,55 @@ Perl will print The behavior of local() on non-existent members of composite types is subject to change in future. +=head3 Localized deletion of elements of composite types +X X X X + +You can use the C and C +constructs to delete a composite type entry for the current block and restore +it when it ends. They return the array/hash value before the localization, +which means that they are respectively equivalent to + + do { + my $val = $array[$idx]; + local $array[$idx]; + delete $array[$idx]; + $val + } + +and + + do { + my $val = $hash{key}; + local $hash{key}; + delete $hash{key}; + $val + } + +except that for those the C is scoped to the C block. Slices are +also accepted. + + my %hash = ( + a => [ 7, 8, 9 ], + b => 1, + ) + + { + my $a = delete local $hash{a}; + # $a is [ 7, 8, 9 ] + # %hash is (b => 1) + + { + my @nums = delete local @$a[0, 2] + # @nums is (7, 9) + # $a is [ undef, 8 ] + + $a[0] = 999; # will be erased when the scope ends + } + # $a is back to [ 7, 8, 9 ] + + } + # %hash is back to its original state + =head2 Lvalue subroutines X X