Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Syntactic Confectionery Delight

Comment on


No they're not :-)

The first is a reference to an array that has every element aliased to every element of @array.

The second is a reference to @array.

The "trick" wouldn't work otherwise, since changing $r2 will change @array. For example.

my @array = (1..10); my $r1 = sub { \@_ }->(@array); pop @$r1; print "unchanged @array\n"; my $r2 = \@array; pop @$r2; print "changed @array\n";

gives us

unchanged 1 2 3 4 5 6 7 8 9 10 changed 1 2 3 4 5 6 7 8 9

In reply to Re^3: Non-destructive array processing by adrianh
in thread Non-destructive array processing by Juerd

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (8)
    As of 2014-03-14 05:56 GMT
    Find Nodes?
      Voting Booth?

      Have you used a cryptocurrency?

      Results (301 votes), past polls