in reply to for loop trouble

Your $hit variable is undefined if your $orth variable doesn't match /^A(\d+)/. You might want to check for that.

Also, you seem to come from a C-like programming language. The loop could be written in a shorter, less error-prone way as

push @hits, grep {/$hit/} @pids; push @potential_hgt, grep {! /$hit/} @pids;

There also is a module which implements the part function, which divides one list into two (or more) lists, which would be quite handy here, but I don't find that module at the moment.

Replies are listed 'Best First'.
Re^2: for loop trouble
by fishbot_v2 (Chaplain) on Aug 12, 2005 at 13:00 UTC
    There also is a module which implements the part function...

    see: List::Part

    use List::Part; my ( $in, $out ) = part { m/$hit/ } @pids;

    Where $in is an arrayref to the matches, and $out to the rest.

Re^2: for loop trouble
by Roy Johnson (Monsignor) on Aug 12, 2005 at 15:03 UTC
    It's not at all onerous to implement part doing just one pass, without a module:
    push @{/$hit/ ? \@hits : \@potential_hgt}, $_ for @pids;

    Caution: Contents may have been coded under pressure.