in reply to Conditional Regex

Not sure what conditionals buy you here:

sub getvalue { my $s = shift; local $_ = shift; return $+ if /$s[:=](?:(\d+)|"([^"]+)"|\s*(.*?)\s\D)/; "Match not Found"; }

Replies are listed 'Best First'.
Re: Re: Conditional Regex
by hsmyers (Canon) on Jan 09, 2004 at 15:26 UTC
    Quite a lot since the original buggy version was $value1 or $value2 or $value3 or 'Match not found'; and since zero was a normal value, this choked on me---hence the if (defined ($value1)) { version. I'd forgotten (if I ever knew) about $+, so I'd have to say I like your version better! Thanks!!

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."