in reply to Re: Re: conditional match in regex
in thread conditional match in regex

Yes, that will work, but yours has the problem that it creates $1, $2, and $3. I wanted to limit the regular expression so that $1 = type, and $2 = name.

Replies are listed 'Best First'.
Re: Re: Re: Re: conditional match in regex
by petral (Curate) on Nov 05, 2002 at 23:08 UTC
    Right, this way $1 = type and $3 = name.  Oh well...

      p

      Actually, $1 = type if the type is $, @, %, or *; however, in the <name> case, the only way to check its type is by nested conditionals outside the regex; something like:

      if ($2) { if ($1 eq '$') { ... } elsif ($1 eq '@') { ... } ... } else { ... }

      Which, IMHO, is a huge pain in the behind compared to a single if-elsif chain. Why do more work than you have to?

        The problem seems to be stated: either $val or <val>:
        $ perl -le'$_=pop;/([\$@*%]|(<))(.*)(?(2)>)/;print"($1)($3)"' '$xyz' ($)(xyz) $ perl -le'$_=pop;/([\$@*%]|(<))(.*)(?(2)>)/;print"($1)($3)"' '$xyz>' ($)(xyz>) $ perl -le'$_=pop;/([\$@*%]|(<))(.*)(?(2)>)/;print"($1)($3)"' '<xyz>' (<)(xyz)


          p