http://www.perlmonks.org?node_id=1055857


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

Thanks Kenneth, I understand your code, but I may have more than one name in the same line, such as:

bananas,peaches,kiwis

peaches,peaches

pineapple

(...)

So we couldn't use that kind of cycling on the array positions, right? Or am I missing something?

Replies are listed 'Best First'.
Re^3: using hashes
by AnomalousMonk (Archbishop) on Sep 26, 2013 at 16:17 UTC
    ... am I missing something?

    You're missing what BrowserUk said here, an approach that processes an entire line at a time.

    The next part to think about is what happens if you encounter a 'word' in a line that doesn't exist in your translation hash, e.g., the line
        "peaches,peaches,foobar,kiwis\n"
    (hints: exists, next, maybe  // (defined-or) or  ?: (ternary/conditional operator) – see perlop for the latter two).