Andrew Gaffney wrote: > david wrote: > > Andrew Gaffney wrote: > > > > > >>I've got an array reference and I'm trying to figure out how many elements > >>are in it. I've tried '$#arrayref', '[EMAIL PROTECTED]', '$(@($arrayref))', and > >>probably a few others that I've forgotten. What is the correct way to do > >>this? > > > > > > you can try @{EXP} or $#{EXP}+1 where EXP is your array reference: > > > > [panda]# perl -le 'print $#{[1,3,5,7]}+1' > > 4 > > [panda]# perl -le 'print @{[1,3,5,7]}+0' > > 4 > > [panda]# > > > > the '{}' is sometimes optional depends on EXP, i usually use it for personal > > perference. > > '$#{$arrayref}+1' worked for me. Thanks. Once again, I don't know what I'd do > without the > people on this list.
Way too complicaqted, I'd say. Just put it in scalar context by assigning the array referenced by it to a scalar: Greetings! E:\d_drive\perlStuff>perl -w -Mstrict my @elements = (1, 'two', 'three', 4); my $array_ref = [EMAIL PROTECTED]; my $count = @$array_ref; print "$count\n"; ^Z 4 Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>