John W. Krahn am Donnerstag, 9. März 2006 03.36:
> Hans Meier (John Doe) wrote:
[...]
> > my @array;
> > #or:
> > my @array=();
[v--- this sidenote is wrong]
> > (sidenote: the second form must be used in contexts where the code is
> > persistent/preloaded and used several times, to ensure that @
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 t
> > From: Graeme McLaren [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, March 08, 2006 3:57 PM
> > To: beginners@perl.org
> > Subject: counting scalar array elements question
> >
> > Hi all, I have an array question:
> >
> > If I have a variable, $var, and it contains an array how would I be able
>
You need to dereference your array ref.
my $count = @{$var};
Or in some circumstances it might make more sense to explicitly use
scalar context:
my $count = scalar @{$var};
-Original Message-
From: Graeme McLaren [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 08, 2006 3:57 PM
T