in reply to Re: Re: expanding the functionality of split
in thread expanding the functionality of split
I'm not convinced that an array-based split would be so easy to work with. I think that looping a simple regex match over an array of delimiters would be easiest for the average programmer to grasp (and maintain); something like:
(Note that the final delimiter in the sequence is assumed to be the final pattern on the line -- i.e. the line terminator.)my @delim_seq = qw/: :: \s+ = \n/; my $string = "a:b::c d=e\n"; my @fields = (); foreach my $delim ( @delim_seq ) { $string =~ s/(.*?)$delim//; push @fields, $1; }
So you have two statements inside a loop, instead of a single statement using "split(...)" -- I could live with that easily enough (whereas I'd worry about adding complexity to a basic function like "split").
|
|---|