in reply to Best way to take reference to an array \ or []
They do different things...
use 5.010; use strict; use warnings; my @array = ('a' .. 'c'); sub get_ref1 { \@array }; # returns a ref to @array sub get_ref2 { [@array] }; # creates an anonymous array and returns r +ef to it my $ref1 = get_ref1(); push @$ref1, 'd'; say "(@$ref1) and (@array) - note 'd' has been added to original array +"; my $ref2 = get_ref2(); push @$ref2, 'e'; say "(@$ref2) and (@array) - note 'e' has NOT been added to original a +rray";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best way to take reference to an array \ or []
by vinoth.ree (Monsignor) on Jan 22, 2013 at 12:33 UTC | |
by muba (Priest) on Jan 22, 2013 at 12:35 UTC | |
by vinoth.ree (Monsignor) on Jan 22, 2013 at 12:46 UTC |