in reply to ignoring empty returns from split

You could knock yourself out, such as:      my ($one, $two) = grep { $_ } split (/exp/, $line); Or, you could just use the split parameters:      my ($one, $two) = split (/exp/, $line, 2); Where 2 is the limit on the number of parameters you want back.

Replies are listed 'Best First'.
Re: Re: ignoring empty returns from split
by lemming (Priest) on Apr 24, 2001 at 02:02 UTC
    Or, you could just use the split parameters:
    my ($one, $two) = split (/exp/, $line, 2);

    This will break for cases of "=0==one=two" since you'll return an empty and a zero.

    For those suggesting a simple $_ test for the grep, you will not return the 0. Best to go with the length() function.

    Update: I'd have to go with Ovid that "length > 0" is clearer than just length, but might there be a performance hit? (And would this code really be hurt by the performance hit?)