Paul Johnson wrote:
> 
> On Fri, Jan 03, 2003 at 06:32:10PM -0800, John W. Krahn wrote:
> >
> > You are saying that it has no name but it does: arrayref.  If it truly
> > had "no name" then there would be no way to access it anywhere else in
> > the program.
> 
> I am saying that an anonymous array has no name, but it can be accessed
> via a reference to it.

In that case the reference name is its name

> I am also saying is that there is no practical difference between
> 
> $ perl -MData::Dumper -e '$aref = [1, 2, 3]; print Dumper $aref'
> $VAR1 = [
>           1,
>           2,
>           3
>         ];
> 
> and
> 
> $ perl -MData::Dumper -e '@$aref = (1, 2, 3); print Dumper $aref'
> $VAR1 = [
>           1,
>           2,
>           3
>         ];
> 
> In each case the array is anonymous and can only be accessed via $aref,
> which is a scalar reference to that array.

In the first example you are assigning the reference of an anonymous
array to a scalar and the expression is in scalar context.  In the
second example you are assigning a list to a dereferenced array and the
expression is in list context.  In both cases, after the expression has
been evaluated, the array has the name 'aref'.  If the array was truly
anonymous there would be no way to access it after the expression was
evaluated.

$ perl -MData::Dumper -Mstrict -wle'
# create an anonymous array and push data to it
# so it must be an array (push, pop, shift, unshift
# and splice only work on real arrays)
push @{ [ 1,2,3,4 ] }, ( 5,6,7,8 );
# how do we display its contents?
# we cant because it is anonymous (no name)!
'
$



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to