in reply to deleting array elements(efficiency/critique)

@{$mon_obj->{FILE_DATA}} = grep{$_}@{$mon_obj->{FILE_DATA}}

Replies are listed 'Best First'.
Re: Re: deleting array elements(efficiency/critique)
by davorg (Chancellor) on Dec 27, 2000 at 20:56 UTC

    It's unclear whether or not the array can contain a valid line which consists of the empty string or the character '0'. either of these possibilities would break your code. This problem can be fixed with:

    @{$mon_obj->{FILE_DATA}} = grep { defined $_ } @{$mon_obj->{FILE_DATA}};
    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      Yes, that's an obvious refinement, which the original loop did not contain,
      presumably because '' and '0' are either not present or not valid
      so I preserved that behavior in the grep condition.