in reply to Re: Transpose a file
in thread Transpose a file
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*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Transpose a file
by choroba (Cardinal) on May 11, 2016 at 13:24 UTC | |
by Discipulus (Canon) on May 11, 2016 at 19:25 UTC | |
|
Re^3: Transpose a file
by NetWallah (Canon) on May 11, 2016 at 13:59 UTC |