Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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?
[LanX]: point is: in high speed trade each bank has to remember what he has to get from the others... so dresdner got billed for losses but couldn't claim gains
Discipulus is this the IT?
[Corion]: Discipulus: Well, in many cases it doesn't make sense to build an interface and complicated program just to enter 20 rows into a database ;) But yes, automating data imports should pay off in the long run
[LanX]: Choroba: this happened before I joined, was still in uni, but my boss was summoned to the CEO of the second biggest German bank at that time and could only say " I told them its not ready" ;)
[LanX]: memories....I missed my connection while chatting
[Discipulus]: in this case Corion we are speaking about software licensing: evry year or two we must rescan the whole ced to produce an excel report, while at every activation / disactivation we update a black box DB: i said that i a week i can produce the perl to..
[Discipulus]: rend out the xls IF i have access to the DB
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-03-29 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.