in reply to ignoring empty returns from split
use strict; use warnings; my $line = "one====two==three"; my ( $one, $two ) = grep { length > 0 } split /=/, $line; print "$one\n$two";
Cheers,
Ovid
Update: Modified code sample to more accurately reflect poster's intention.
Update 2: tadman does raise a point about grep{length} being sufficient. I'm of the opinion that while this may be sufficient, it might not be as immediately clear to the casual observer as grep{length>0}. Any monks care to comment on the style issue?
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: ignoring empty returns from split
by tadman (Prior) on Apr 24, 2001 at 01:45 UTC | |
|
Re: (Ovid) Re: ignoring empty returns from split
by DeusVult (Scribe) on Apr 24, 2001 at 19:38 UTC | |
by busunsl (Vicar) on Apr 24, 2001 at 19:47 UTC |