Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^7: using hashes

by kennethk (Abbot)
on Sep 27, 2013 at 15:41 UTC ( #1056010=note: print w/replies, xml ) Need Help??


in reply to Re^6: using hashes
in thread iterating hash keys?

Hyphens aren't special outside of a character class. What makes you think they are at fault?

If your 'words' might contain punctuation, you can escape meta characters using quotemeta or synonymously \Q .. \E

s/\b\Q$find\E\b/$replace/g

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^8: using hashes
by R56 (Sexton) on Sep 27, 2013 at 17:48 UTC

    Imagine these values:

    banana => 25

    bana => 20

    bana-na => 15

    na => 10

    For the translation to, let's say:

    bana-na,banana

    Currently the output is:

    20-10,25

    That's what made me thought the hyphens were a special case...

      No, but they are being marked as word boundaries, and so they pass the regex I gave before. For the situation you've described, the only obvious solution I can see is to traverse the key list from long to short as I've shown in Re^5: using hashes. Things get messy with replacement lists when your keys are not independent.


      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        I see... Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056010]
help
Chatterbox?
[marioroy]: choroba++, Discipulus++. It depends on the type of module. Data-type "only" modules are likely multi-process safe, re: Hash::Ordered, Tie::IxHash.
[marioroy]: ... when shared via MCE::Share-> share(...)
[marioroy]: Net type modules are likely not multi-process safe unless stated in the documentation.
[marioroy]: The Prima author fixed his module to be both thread and multi-process safe. Thanks Dmitry.
[marioroy]: Of all the GUI-type modules, Prima was the worst regarding thread/multi- process safety. Now, it's the best for safety. ;-)
[marioroy]: Tk, Gtk2, Gtk3 requires extra care.
[marioroy]: I was unable to run parallel with Win32::Console. Fortunately, running parallel behind Win32::API is possible.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-09-22 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (260 votes). Check out past polls.

    Notices?