Differences between version 30 and revision by previous author of PerlOneLiners.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 30 | Last edited on Friday, August 26, 2005 2:42:04 am | by AristotlePagaltzis | Revert |
Older page: | version 28 | Last edited on Thursday, August 25, 2005 9:55:14 am | by JohnMcPherson | Revert |
@@ -54,19 +54,21 @@
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"
}
}'
</verbatim>
-This
will read whitespace-separated tabular data from stdin(3) or from the files passed, and will write to tab-separated tabular data to stdout(3).
+Both of these
will read whitespace-separated tabular data from stdin(3) or from the files passed, and will write to tab-separated tabular data to stdout(3).
!! Trace execution in a [Perl] script
Getting a trace showing each executed line of code in sequence (think <tt>sh -x</tt> but for [Perl] scripts) is not obvious. perl(1)'s <tt>-D</tt> switch itself does not provide such functionality, but you can get there like so: