Very nice. :) You almost got it all. However,

$_= '.' . chr ord
is not exactly the same thing as
$_= '.'.$_
Consider this:
${_} = q...q,.,.qq,$=,^q.$..$=; print ord() . "," foreach(split//);
and then try to replace like this:

for(;$_?$,:(${_} = q...q,.,.qq,$=,^q.$..$= => $_=q,.,.$_ );) {
It destroys the output (or should, at least). This is because ord returns the value of the first character in the string it is fed. There is a difference. If you replace all the way down to $_="\n" then it works again, of course. :)

For more clarity,

for(s//Just another perl hacker/) {
is really

foreach(s//Just another perl hacker/) {
- although they are interchangeable syntax-wise in perl.

I don't know if you used it, but sadly deparsing gives a lot away. What I do think is funny is that deparsing translates one for to while, one to foreach and leaves the last as a for:

while ($_ ? $, : ($_ = '.' . "$=" ^ '$' . $=, $_ = '.' . chr(ord $_))) + { foreach $_ (s// Just another perl hacker/) { (); } for (; s/.//; print $_) { (); } }
Then again, I guess I am easily amused.

I like your initial reminder too - that was exactly what this was "about" - abusing the for construct, which is also a bit special in perl. :)

And oh, there is one more stripping possible to do - to get to approximately where I started (using your example):

$_=".\n"; s//Just another perl hacker/; while (s/.//) { print; }
Neither of the for loops has any real reason to be nested into any other - it is really just three separate lines of code.

Thank you for taking the time - it is appreciated. :)


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

In reply to Re: Re: foreach(silly..japh) by Dog and Pony
in thread foreach(silly..japh) by Dog and Pony

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.