When you incorporate @array into a double-quoted construct it is interpolated as a list of elements, rather than with scalar context. The list separator in double-quoted constructs is usually " " (the space character), but can be changed to just about anything by setting $".
So you might think, "Well, I'll just do this: print @array, "\n";.", which would be wrong again, because once again @array is being evaluated in list context, which just returns the elements (this time separated by whatever is set in "$,".
You have to give @array scalar context. Here are a couple of ways:
my $size = @array; print "$size\n"; # or... print scalar(@array), "\n"; # or .. print @array . "\n"; # Because '.' invokes scalar context on its opera +nds.
Dave
In reply to Re: Counting elements in array
by davido
in thread Counting elements in array
by finfan
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |