Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: Re: Re: conditional match in regex

by jryan (Vicar)
on Nov 06, 2002 at 08:09 UTC ( [id://210682]=note: print w/replies, xml ) Need Help??


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

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?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: conditional match in regex
by petral (Curate) on Nov 06, 2002 at 14:58 UTC
    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
      '$xyz>' is definately NOT a valid symbol table entry.
        Right.  I was just showing how the regex works.
        $ perl -le'"%xyz"=~/([\$@*%]|(<))(.*)((?(2)>))/;print"($1)($3)($4)"' (%)(xyz)() $ perl -le'"%xyz>"=~/([\$@*%]|(<))(.*)((?(2)>))/;print"($1)($3)($4)"' (%)(xyz>)() $ perl -le'"<xyz>"=~/([\$@*%]|(<))(.*)((?(2)>))/;print"($1)($3)($4)"' (<)(xyz)(>)

          p

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://210682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-19 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found