in reply to Test Number of Elements In Array

but not sure if that really works...
Then just test it for yourself:
use strict; use warnings; my @a0; my @a1 = 1; my @a2 = 0..5; check(@a0); check(@a1); check(@a2); sub check { if (@_ == 1) { #if ((scalar @_) == 1) { print "exactly 1\n"; } else { print "diff from 1\n"; } } __END__ diff from 1 exactly 1 diff from 1

Your original method seems to work pretty well.

You could make it more verbose by using scalar. You decide which is simpler for you to understand.

Replies are listed 'Best First'.
Re^2: Test Number of Elements In Array
by AnomalousMonk (Archbishop) on Jun 05, 2009 at 17:32 UTC
    You could make it more verbose by using scalar.
    More verbose, but absolutely unambiguous to the future reader, who may even be the original author.

      If a future reader does not understand scalar context in Perl (especially in this hoary idiom for counting the number of elements in an array!), you have far greater worries than whether he or she will understand this expression.