Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: using hashes

by R56 (Sexton)
on Sep 27, 2013 at 13:26 UTC ( #1055979=note: print w/replies, xml ) Need Help??


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

Is there a simple way to also contemplate names with hyphens on the middle?

Replies are listed 'Best First'.
Re^7: using hashes
by kennethk (Abbot) on Sep 27, 2013 at 15:41 UTC
    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055979]
help
Chatterbox?
[Corion]: Oh yay. I wonder why a very simple change in a program doesn't elicit a diff, and now I see that my diff program seems to have a bug ;)
[1nickt]: marto thanks for asking, so far so good. A pretty modern stack and decent procedures, although rather too much home-built stuff (e.g. a logging role that should tries to duplicate Log::Any).
[Corion]: No. It's just that I'm comparing the same output file twice, instead of comparing the output files of the two runs %-)
[Corion]: Lo and behold, running a program with the correct input files yields the correct (and expected) output. Yay me.
[1nickt]: Got a MacBook and am expected to develop directly on it, ironic given the recent thread about that.
[marto]: Corion, some not too serious issues with the kids, hopefully, other than that just dealing with commuting by car again in the winter, not much fun so far, and there's no real 'bad' weather yet :)
[marto]: 1nickt, glad to hear it, I'm sure you'll bring improvements to their stack in due course ;)
[1nickt]: Just trying to adjust to a new culture. Better doc than I am used to , but quite a bit more Agiley meta-bullshit; at least half a dozen meetings a week, strict "sprint" schedule etc. I'll adjust. And I hope to just switch off after the "scrum" each day at
[1nickt]: ... the end of the afternoon. marto How are you, snowed in? Mum and Dad expecting snow today in Surrey. (Have 5" on the ground here in NJ. And my son's high school in SOCal closed until after Xmas due to fires.)
[Corion]: 1nickt: In a sense the meta-bullshit might even be beneficial to you as you get to hear the cow-orkers talk (or not talk) about the issues you perceive. I think Agile is mostly about the meta ;)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-12-11 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (289 votes). Check out past polls.

    Notices?