in reply to Re: list reversal closure
in thread list reversal closure

Nit to your nit :) Notice the -l on his shebang line.

C:\test>perl -e" print for reverse 1.. 10" 10987654321 C:\test>perl -le" print for reverse 1.. 10" 10 9 8 7 6 5 4 3 2 1

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: list reversal closure
by apotheon (Deacon) on Aug 21, 2006 at 19:17 UTC

    Thanks for bringing that up in response. You're right: eliminating the for() changes the intended behavior of the program.

    Now, I suppose, a new question has arisen: Should I intend for every list element to be printed on a separate line, or should I intend for the list to have its own line as in ikegami's example? It's not particularly critical either way, but perhaps there's an aesthetic benefit to be had from one or the other approach.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin

Re^3: list reversal closure
by ikegami (Patriarch) on Aug 21, 2006 at 16:05 UTC

    You did not contradrict me. I did say as long as $, and $\ are equal. -l changes $\, but not $,. This actually makes the version without for more flexible!

      This actually makes the version without for more powerful!

      Maybe, maybe not. Setting $, equal to $/ compromises your ability to use both for their designated purpose:

      @array = map{ [ 'a'..'f' ] } 1 .. 6;; print @$_ for @array;; a b c d e f a b c d e f a b c d e f a b c d e f a b c d e f a b c d e f

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Apples and oranges. We were talking about print for reverse vs print reverse. for clearly compromises it:

        $, = ", "; $\ = "\n"; @array = map{ [ 'a'..'f' ] } 1 .. 6;; for (@array) { print for reverse @$_; } __END__ f e d c b a f e d c b a f e d c b a f e d c b a f e d c b a f e d c b a
        $, = ", "; $\ = "\n"; @array = map{ [ 'a'..'f' ] } 1 .. 6;; for (@array) { print reverse @$_; } __END__ f, e, d, c, b, a f, e, d, c, b, a f, e, d, c, b, a f, e, d, c, b, a f, e, d, c, b, a f, e, d, c, b, a

        Updated to use parent's @array.