Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Do nothing? or Do something important in a very obscure way?

by blakem (Monsignor)
on Aug 23, 2002 at 10:49 UTC ( #192299=note: print w/replies, xml ) Need Help??

in reply to Do nothing? or Do something important in a very obscure way?

/x?/ means match x zero or one times, but prefer 1...
i.e. Match it if you can

/x??/ means match x zero or one times, but prefer 0...
i.e. Match it if you have to

For instance:

% perl -le '"wxy" =~ /(wx?)/; print $1' 1:wx % perl -le '"wxy" =~ /(wx??)/; print $1' 1:w % perl -le '"wxy" =~ /(wx?y)/; print $1' 1:wxy % perl -le '"wxy" =~ /(wx??y)/; print $1' 1:wxy
The notation is a little confusing because the two question marks in a row mean different things. /x?/ is really just syntatic sugar for /x{0,1}/. The second question mark turns on min matching. When you look at it this way, the difference between /x{0,1}/ and /x{0,1}?/ should be more clear.


Replies are listed 'Best First'.
Re: Re: Do nothing? or Do something important in a very obscure way?
by BrowserUk (Pope) on Aug 23, 2002 at 10:58 UTC

    Makes sense in terms of Perl5 regex's, but in the original context of Exegesis5 where the 'x??' and 'x*?' are followed by the Perl6 'don't backtrack' ':' operator, I am not so sure?

    What's this about a "crooked mitre"? I'm good at woodwork!
      Ah, I see now.... /x??:/ will behave exactly like /x{0}/
      In english /x??:/ would read something like this:

      Match 'x' zero or one times, prefer 0 over 1, lock in the first value that allows this atom to match (i.e. don't backtrack).

      Since the 0 will always cause the atom to match, the engine will never be allowed to try the 1.

      I know thats not the best description.... hope it helps.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://192299]
choroba waves
[Mj1234]: Hello Monks, I have installed Active perl 5.16 and 5.14 but I dont find Devel::GDB package when I try to install through ppm
[Discipulus]: i'v installed ubuntu 16.04lts and i'm quite disappointed: is deadly simmilar to new win osses where you cannot find even simple things...
[Corion]: Hi Discipulus ;)
[Corion]: Mj1234: Maybe Ubuntu didn't package Devel::GDB? In that case, consider using local::lib and install the module from CPAN
[Corion]: But a quick Google search turns up this page, which seems to suggest that it should be packaged
[Discipulus]: iirc active perl has repositories only for last 2 o 3 major release of perl Mj1234. I strongly suggest portable version of strawberry perl and use cpan client to install modules

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2016-12-07 08:51 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (125 votes). Check out past polls.