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
To: [email protected]
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
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:
my $var = [
'a',
'b',
'c'
]
and I tried:
push @array, $var;
and got:
@array=[
[
'a',
'b',
'c'
]
]
Using my original array which is assigned to scaler, what I need is:
@array = [
'a',
'b',
'c'
]
So I can do:
my [EMAIL PROTECTED];
Can anyone shed any light on this or suggest a better way of doing this?
Cheers,
G :)
Public Sub House()
On Error Resume drink
If Pint.empty = True Then
Pint.refill
Else
Pint.drink
End if
stomach.add Pint
MsgBox " I've had .... " & stomach.count & " Pints"
MsgBox "VERY DRUNK"
End Sub
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>