24716Re: [PBML] Counting elements of Array
- Dec 15, 2006Hello All,
I'm so sorry. I read about it in somewhere that I dont remember. I only ask you because I cant find it on the context. I'm really sorry.
The len is exactly what i need.
Thanks a lot,
Jenda Krynicky <Jenda@...> wrote: From: 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
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
[Non-text portions of this message have been removed]
- << Previous post in topic Next post in topic >>