in reply to Re^2: Transposition of each letter pair in string
in thread Transposition of each letter pair in string
++, 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Transposition of each letter pair in string
by Aristotle (Chancellor) on Dec 29, 2002 at 17:05 UTC |