and iterate through all the hash keys
The major purpose of hashes is that you can lookup the value associated with any key directly, avoiding iteration.
For your purpose, the major part of the code should be something like:
while( <$names_to_be_replaced_file> ) { ## read each line s[\b([a-z]+)\b][ $name_id{ $1 } ]ge; ## find words, look them up + and replace them with the id print; ## Send the modified lines +to stdout }
Simple and very efficient.
In reply to Re: using hashes
by BrowserUk
in thread iterating hash keys?
by R56
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |