Rob,

I will take your word that "$a = (3, 2, 1);" returns 1.  I think I was
thinking of "$a = [3, 2, 1];", in which an anonymous array would be
created and $a would return 3, the number of elements in the array.

NOT!!!

The above is what I was going to say when I started typing this, but
then I remembered.  In "$a = [3, 2, 1];", $a gets a reference to the
anonymous array.  I was going to finish this thought with a way to get
the number of elements in the anonymous array, but I realized I don't
know how!  Also, this question could be important in my current
project.  What's the best way to find the number of elements contained
in an anonymous array to which you have a reference?

Thanks yet again!

RobR

Previous discussion retained since I'm not sure if it went out to the
list or not.

--- Rob Dixon <[EMAIL PROTECTED]> wrote:
> 
> ----- Original Message -----
> From: "Rob Richardson" <[EMAIL PROTECTED]>
> To: "Rob Dixon" <[EMAIL PROTECTED]>
> Sent: Friday, December 20, 2002 1:30 PM
> Subject: Re: Passing array to a function
> 
> 
> > Rob,
> >
> > OK, I see what you're talking about now.  Yes, they are clearly
> > different.
> >
> > I've got a question about one of your examples:
> > >     $a = (3, 2, 1); # sets $a to 1 (the last list element)
> > In this case, wouldn't (3, 2, 1) be converted internally into an
> array?
> >  Then that line would be equivalent to
> > @x = (3, 2, 1);
> > $a = @x; # sets $a to 3 (the number of elements in the array)
> >
> > I've got to get Perl installed here at work so I can try out these
> > things for myself.
> 
> Well, have you tried it yet? And am I right? =)
> 
> Setting a scalar to a list value should, I suppose, strictly be
> illegal. But
> Perl tries to do something useful when you write nonsense, so it
> behaves in
> this case as if the comma list separator is actually the comma
> operator
> whose value is simply its right-hand operand. I put it in there as
> the most
> obvious example of the ditinction between lists and arrays.
> 
> In reality subroutines can only return data, which is either list
> data or
> scalar data. Putting this data into structures (arrays, hashes, or
> anything
> more complex) adds semantics to the data, and the only way to retain
> this is
> to return a (scalar) reference to a data structure.
> 
> HTH,
> 
> Rob
> 
> 
> 
> 
> 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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

Reply via email to