Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all, Can you please tell me what's the difference between these two types of getting the reference to @a array? my $ref = [ @a ]; and my $ref = \@a; If I do: use Data::Dumper; print Dumper $ref; Both ways of accesing the @a array with a reference seems to be the same, because Data::Dumper prints the same thing for $ref. I need to access an array reference in a module, like... my $self = [ @a ]; or... my $self = \@a; and I don't know if there will be any differences... Thank you much. Teddy
Post Follow-up to this messageOctavian Rasnita wrote:
> Hi all,
Hello,
> Can you please tell me what's the difference between these two types of
> getting the reference to @a array?
>
> my $ref = [ @a ];
This copies the array to an anonymous array and returns a reference to that
anonymous array. It is equivalent to:
my $ref = do { my @temp = @a; \@temp };
> and
> my $ref = \@a;
This returns a reference to the array.
> If I do:
> use Data::Dumper;
> print Dumper $ref;
>
> Both ways of accesing the @a array with a reference seems to be the same,
> because Data::Dumper prints the same thing for $ref.
>
> I need to access an array reference in a module, like...
>
> my $self = [ @a ];
> or...
> my $self = \@a;
>
> and I don't know if there will be any differences...
It depends on the scope of @a.
John
--
use Perl;
program
fulfillment
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.