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

Re^2: Parsing with perl - Regexes and beyond

by tybalt89 (Prior)
on Sep 20, 2016 at 22:33 UTC ( #1172254=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing with perl - Regexes and beyond
in thread RFC: Parsing with perl - Regexes and beyond

I tried running this code. Sometimes it worked and sometimes it failed.

Unusual for perl...

Then I remembered that recently hashes were randomized = bingo!

The line

my $reOps = qr[@{[ join '|', map{ quotemeta } keys %ops ]}];

needs to be changed to

my $reOps = qr[@{[ join '|', map{ quotemeta } sort { length $b <=> length $a } keys %ops ]}];

to keep * from being matched before **

Replies are listed 'Best First'.
Re^3: Parsing with perl - Regexes and beyond
by BrowserUk (Pope) on Sep 20, 2016 at 23:30 UTC

    Your correction needs a small correction:) We need to do the sort by length after the quotemetaing:

    my $reOps = qr[@{[ join '|', sort { length $b <=> length $a } map{ quo +temeta } keys %ops ]}];

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Parsing with perl - Regexes and beyond
by Discipulus (Abbot) on Sep 22, 2016 at 08:09 UTC
    are you finally got an account? i suspect (and wish) you are one of the quality AnonymousMonk used to lurk here around.

    Anyway welcome to the monastery tybalt89!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Thank you!

      Your suspicion is correct, I have been lurking around. Most of my AnonymousMonk postings can be identified by the code block having the thread URL in a comment on the third line, like Re^2: Parsing with perl - Regexes and beyond in this thread.

Re^3: Parsing with perl - Regexes and beyond
by BrowserUk (Pope) on Sep 20, 2016 at 22:56 UTC

    Thanks for the heads up. I'll amend the post above with your fix just in case someone else comes looking.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-10-31 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?