Hans Meier (John Doe) wrote:
>>>From: Graeme McLaren [mailto:[EMAIL PROTECTED]
>>>
>>> If I have a variable, $var, and it contains an array how would I be
>>> able to easily count the number of elements in the array?  I've tried
>>> creating a new array and pushing the original array on to it but that
>>> creates an array of arrays.
>>>
>>> Basically I have:
> 
> use strict;
> use warnings;
> 
>>> my $var = [
>>>                 'a',
>>>                 'b',
>>>                 'c'
>>>               ]
> 
> # shorter: 
> 
> my $var=[ qw/ a b c / ];
> 
>>> and I tried:
> 
> my @array;
> #or:
> my @array=();
> 
> (sidenote: the second form must be used in contexts where the code is 
> persistent/preloaded and used several times, to ensure that @array is always 
> empty when the next execution hits the code again. Of course only *if* it 
> should start empty and not accumulate between executions)

Are you sure about that?  Do you really understand what my() does?


>>> push @array, $var;
>>>
>>>
>>> and got:
>>>
>>> @array=[
>>>                [
>>>                   'a',
>>>                   'b',
>>>                   'c'
>>>                ]
>>>          ]
> 
> You probably got this AoA (array of arrays) by using 

You mean AoAoA (Array of Arrays of Arrays.)



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to