in reply to Re: Transpose a file
in thread Transpose a file

OK and ++NetWallah but now you explain this to me: at first glance i saw the BEGIN and seemed to me not necessary, but after a while I saw $c++}  { part and i said: this is a typo.. but no! it compiles and run fine as all code you post.

Removing the BEGIN block..

perl -na -E "$x[$_][$c||0]=$F[$_] for 0..$#F; $c++} {say qq|@$_| for +@x"

..deparsed becomes:

BEGIN { $^H{'feature_unicode'} = q(1); $^H{'feature_say'} = q(1); $^H{'feature_state'} = q(1); $^H{'feature_switch'} = q(1); } LINE: while (defined($_ = <ARGV>)) { our(@F) = split(' ', $_, 0); $x[$_][$c or 0] = $F[$_] foreach (0 .. $#F); ++$c; } { say "@$_" foreach (@x); }

So your evil trick ;=) to use } { is to break the implicit loop created by -n ? and doing so you have a fictional END block?

If so, I prefere (in this case) readabilty over magic:

perl -na -E "$x[$_][$c||0]=$F[$_] for 0..$#F; $c++; END{say qq|@$_| for @x}"

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Transpose a file
by choroba (Cardinal) on May 11, 2016 at 13:24 UTC
    > evil trick

    See "Eskimo greeting" in perlsecret.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      noo there is something here around called perlsecret and nobody told me?!

      thanks choroba i'll open the link next christmas.. ;=)

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: Transpose a file
by NetWallah (Canon) on May 11, 2016 at 13:59 UTC
    Thanks for the de-parse (++). I will agree with you on the readability of the END block vs Eskimo greeting.

    In the same spirit, I think the $c=0 initialization in the BEGIN block is clearer than [$c||0].

            This is not an optical illusion, it just looks like one.