in reply to split post match
use strict; use Data::Dumper; my $string = '=123=123=435'; my @array = grep { $_ ne '' } split '=', $string; print Dumper \@array;
You may need to adjust the grep for your needs.
Oh, and in case anyone considers the golfish grep{$_}, remember that this disallows all false values, such as 0 and 0.0.
I am wondering about the first two answers to your post. They match your problem spec closer than my solution. However, mine appears more robust (what happens if the first element isn't the pattern?). Bad data is always to be expected. I think my solution would be slower, but is the robustness enough to offset the that? Depends upon the speed and your needs.
Cheers,
Ovid
Update:
Oops. Abigail is right: '0.0' is true. Good point about the robustness, too. Ugh.Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: split post match
by Abigail (Deacon) on Jun 21, 2001 at 03:40 UTC |