in reply to ignoring empty returns from split

I think this can be done by choosing the split-regexp carefully:

$line="one===two==three===four"; ($one,$two,$three,$four)=split (/=+/,$line); print "$one\n$two\n$three\n$four";

The + in the expression effectively tells split to treat multiple delimiters as one.

Hope that helps
Brother Ade

Update
Bug killed: $a!=$line, thanks sachmet...

Replies are listed 'Best First'.
Re: Re: ignoring empty returns from split
by sachmet (Scribe) on Apr 24, 2001 at 04:11 UTC
    That fails on the case where $line starts with a =:
    $line = "==one==two==three"; ($one,$two,$three,$four)=split (/=+/,$line); print "$one\n$two\n$three\n$four";
    gives me an undef, 'one', and 'two'.

    As a side note, '$line' != '$a' :-)

    Afterthought: This would work:
    $line = "==one==two==three=four"; ($one,$two,$three,$four)=split (/=+/,($line=~/^=*(.*?)$/,$1)[1]); print "$one\n$two\n$three\n$four";