in reply to Regex issues
I dislike using regexes when simple string functions can handle the job.
By extracting the magic delimiter characters into a predefined constant, the code is clearer and more easily extendable. split will partition an input string on any of those special characters, and the wrapper (xx)[0] extracts the first element from the resulting list.
my @DELIMS = (qw( _ @ )); for my $elem ( @inputs ) { push @result, ( split /[@DELIM]/, $elem )[0]; }
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex issues
by AnomalousMonk (Archbishop) on Jul 13, 2013 at 13:05 UTC | |
Re^2: Regex issues
by Anonymous Monk on Jul 13, 2013 at 08:02 UTC |
In Section
Seekers of Perl Wisdom