++, but why the complicated map games? :)

I had it without "for" first. print takes a list, map creates one. It made sense. But it all was printed on one line, so I added -l and for to make it print every item on its own line.

When it functioned correctly, I pasted it in my web browser, and formatted it. Whenever you see me write $\ = "\n"; here, it's safe to assume I used only the command line to code and test, and used -l there.

If I were to rewrite it, I'd probably have map generate strings that include \n as follows:

my $foo = 'thisisatest'; print map { substr((my $bar = $foo), $_, 2, reverse substr $foo, $_, 2); "$bar\n"; } 0 .. -2 + length $foo;

map feels natural to me. I use it a lot, and love it.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Re: Re^2: Transposition of each letter pair in string by Juerd
in thread Transposition of each letter pair in string by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.