in reply to Re: Translating letters
in thread Translating letters

Well at the moment, I am doing:
foreach (@words) { tr/abcdef/123456/; print @words; }
And the contents of @words are read in from a file. But eventually it will look messy (I think) so I was just wondering of a good/better way to do it (if there are any)

Replies are listed 'Best First'.
Re^3: Translating letters
by BrowserUk (Patriarch) on Apr 15, 2012 at 17:56 UTC
    But eventually it will look messy (I think)

    That doesn't look "messy" to me? Maybe you could post an example of what you think it might "eventually" look like?


    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.

    The start of some sanity?

      Thanks, I did half of the tr/ with a range and the other half normally for each char I wanted to replace with :-)

        One possibility worth considering when you have a complex mapping sequence that doesn't lend itself to simple ranges, is to use bracketing delimiters and spread the construct over two lines:

        $s = join'', 'a'..'z';; $s =~ tr[abcdefghijklmnopqrstuvwxyz] [96537214058751230498763202];; print $s;; 96537214058751230498763202

        Has the advantages of avoiding overly long lines whilst making the mapping very clear.


        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.

        The start of some sanity?