Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by petral (Curate)
on Nov 05, 2002 at 23:08 UTC ( #210598=note: print w/replies, xml ) Need Help??


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

Right, this way $1 = type and $3 = name.  Oh well...

  p
  • Comment on Re: Re: Re: Re: conditional match in regex

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: conditional match in regex
by jryan (Vicar) on Nov 06, 2002 at 08:09 UTC

    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
        '$xyz>' is definately NOT a valid symbol table entry.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-05-30 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (171 votes). Check out past polls.

    Notices?