Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: using hashes

by BrowserUk (Pope)
on Sep 26, 2013 at 17:09 UTC ( #1055866=note: print w/ replies, xml ) Need Help??

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

Is the $1 var pointing to the value of the hash?

$1 captures the words in the string one at a time. This $hash{ $1 } looks that word up in the hash and returns the associates value (id). The ge causes the ids to be substituted for every word in the line.

Perhaps this will clarify things?

%hash = ( brown=>1, fox=>2, quick=>3, the=>4 );; $line = 'the quick brown fox';; $line =~ s[\b([a-z]+)\b][ $hash{ $1 } ]ge;; print $line;; 4 3 1 2

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

Comment on Re^3: using hashes
Select or Download Code
Replies are listed 'Best First'.
Re^4: using hashes
by R56 (Acolyte) on Sep 26, 2013 at 18:21 UTC

    Yes, it did!

    Your solution combined with Kenneth's apparently did the trick. Will try to work around it a little bit tho, see if I can make it quicker.

    Thanks for the help :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-11-25 21:51 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (691 votes), past polls