24714Re: [PBML] Counting elements of Array
- Dec 14, 2006From: Marcos Onisto <mlonisto@...>
> How can I count the elements of one array? I'm using the pushpush() is used to add elements to arrays, not for getting their
> function, but this is return message like below.
> -bash-3.00$ ./checksrvs.pl
> Useless use of push with no values at ./checksrvs.pl line 68.
length or anything.
There is one important and unusual concept in Perl that you simply
have to learn and understand. Context. Expressions return different
values based on the context! Please try to read up on context in your
book or some docs.
Eg. in case of arrays, if the list context the value of an array is
the list of its elements, in scalar context it's the length of the
my @a = (1,2,3);
my @b = (4,5);
my @c = (@a, @b); # list context
my @copy = @a; # list context as well
print "\@c = (@c)\n";
my $len = @a; # scalar context
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
- << Previous post in topic Next post in topic >>