in reply to Re^2: Using undef scalar as arrayref
in thread Using undef scalar as arrayref

if you're doing the for (@arrayref) { ... } as the only statement within the if() test, you don't have to do the if (@$arraytest) part; if the array is empty, the code within in the for() loop won't be executed.

Replies are listed 'Best First'.
Re^4: Using undef scalar as arrayref
by shemp (Deacon) on Aug 12, 2005 at 21:07 UTC
    Actually the if is separate from the loop. If there are any elements in the arrayref a flag needs to be set for later that is separate from what is happening in the loop. So its something like this:
    if ( $arrayref && @$arrayref ) { # set the flag } ... foreach my $element (@$arrayref) { # do stuff }
    Of course i could set it in the loop, but then its being set multiple times.

    I use the most powerful debugger available: print!