in reply to Getting regular expression right
I'd do something like:
It would even be simpler if you used one kind of delimiter, say the pipe. Then you could do:if (/$_[0] =~ /^([^:]+):([^|]+)(?:\|(.*))?$/ || $_[0] =~ /^([^|)+)\|(.*)$/) { @key{qw /name definition altdefinition/} = ($1, $2, defined $3 ? $ +3 : "") }
I certainly wouldn't call by sub 'split'.if ($_[0] =~ /\|/) { @key{qw /name definition altdefinition/} = split /\|/, $_[0]; $key{altdefinition} = "" unless defined $key{altdefinition}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting regular expression right
by mellin (Scribe) on Feb 15, 2005 at 12:06 UTC | |
by Anonymous Monk on Feb 15, 2005 at 12:12 UTC | |
by mellin (Scribe) on Feb 15, 2005 at 12:25 UTC | |
by Anonymous Monk on Feb 15, 2005 at 13:08 UTC | |
|
Re^2: Getting regular expression right
by mellin (Scribe) on Feb 15, 2005 at 11:03 UTC |