got 3 of those replies to work - thank you! i like the quick and dirty regex way.... | [reply] |
if ($args =~ /(?:\A|\s)-iL(?:\s+([^\s]+)|\s*\Z)/) {
print "Found -iL, the value is ", (defined($1) ? "'$1'" : 'absent'),
+ "\n" ;
}
which:
- will not find -iL at the end of some word, eg Tref-iL. (Surprisingly there doesn't seem to be a cleaner way of expressing "whitespace or start of string".)
- uses [^\s] rather than \w -- assuming less about the value of the thing after -iL. (The original fragment used split(/\ /, ...), so strictly should use \ not \s... I have my poet's licence, if you want to see it.)
- will find a -iL even if it's the last thing in the $args, which may or may not be a good thing to trap as an error in the input.
Sadly, this doesn't look as pretty any more :-(
Oh. And FWIW, none of this will cope if the $arg string contains quoted elements -- something way smarter is required ! | [reply] [d/l] [select] |