Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by TheDamian (Priest)
on Aug 23, 2002 at 17:50 UTC ( #192392=note: print w/ replies, xml ) Need Help??


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

What does x<0> mean?

It means "Don't do anything", or rather: "ignore that x". Just as x{0} does in Perl 5.

Don't accept an x here?

No. That's <!before x> in Perl 6. Or (?!x) in Perl 5.

Which is not the same as "Accept something that isn't an x". That would be <-[x]> in Perl 6 and [^x] in Perl 5.


Comment on Re: Re: Re: Do nothing? or Do something important in a very obscure way?
Select or Download Code
Re: Re: Re: Re: Do nothing? or Do something important in a very obscure way?
by pilgrim (Monk) on Aug 23, 2002 at 18:35 UTC
    Precisely. Let's ignore the syntax and mechanics, and re-examine the question (just in case it's helpful):

    A regex is a way to find something in something else. When building one, you have to consider carefully what it is you're trying to find, as well as where you're trying to find it.

    The root of this confusion was, "Why would I want to find none of something?"

    If you've got an irregular something to find, based around regular features, you would want to find none of the irregular (but expected) things, all of the regular features, and would want to be able to fail on unexpected irregularities.

    Similarly, if you've got something you want to find "no matter what", you could try to find it with no whitespace or punctuation (so that "important" would be the same as "*important*" and "I!M!P!O!R!T!A!N!T" and suchlike).

    These are probably bad examples, as I do not write complicated regexes myself, but I think the context is correct.
Re: Re: Re: Re: Do nothing? or Do something important in a very obscure way?
by BrowserUk (Pope) on Aug 23, 2002 at 18:36 UTC

    Skipping over the notion that I can't actually see why anyone would write "Oh here's an x, just ignore it!" unless there is some way to have n in x<n> (x{n}) supplied by a variable such that it read ignore this if n==0, having demonstrated my lack of expertise with regexes, I'm prepared to accept that the construction may have uses I am unaware of.

    Thankyou, it's been an educaton.

    I look forward to Perl6 Grammers and Rules with relish.


    What's this about a "crooked mitre"? I'm good at woodwork!
      Actually, what x{0} says is "succeed if there are zero x'es here". And that's always true, because we can always match none of something, even in an empty string. So basically, x{0} is a NOP, and so is x??: and x*?:.

      Makeshifts last the longest.

        Actually, that's exactly what I thought it meant, hence the "Do nothing?" in the title.

        I remember the days when I used to be obliged to put blocks of NOP's into my assembler subroutines (we used a ratio of 1::20 active instructions) to allow space for remedial patching of the executable, but I couldn't see why you would add them to a regex!


        What's this about a "crooked mitre"? I'm good at woodwork!
      ...unless there is some way to have n in x<n> (x{n}) supplied by a variable...

      There is. And it's probably exactly what you would have expected: x<$n>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-10-23 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (129 votes), past polls