Differences between version 29 and revision by previous author of PerlOneLiners.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 29 | Last edited on Friday, August 26, 2005 2:34:26 am | by AristotlePagaltzis | Revert |
Older page: | version 28 | Last edited on Thursday, August 25, 2005 9:55:14 am | by JohnMcPherson | Revert |
@@ -54,11 +54,13 @@
for $row (@rows) {print $row->[$i] . "\t"}
print "\n"
}'
</verbatim>
-or alternatively:
+
+Alternatively you can let [Perl] do the drudgework work for you. In the following, <tt>-n</tt> implies the <tt>while(<>){}</tt> loop and the <tt>-a -F''regex''</tt> imply the <tt>split</tt> (the result is stored in the predefined <tt>@F</tt> array). Anyone who is at all familiar with [AWK] should follow along easily.
+
<verbatim>
-perl -F
'\s+' -ne'push @rows, [ @F ]; END {
+perl -aF
'\s+' -ne'push @rows, [ @F ]; END {
for $i ( 0 .. $#{ $rows[0] } ) {
for $cols ( @rows ) { print $cols->[ $i ] . "\t" }
print "\n"
}