I found this awk snippet in news:comp.lang.fortran this
morning, and it made me realize that I don’t use Ruby as a
*nix filter as often as I probably should because I couldn’t
duplicate the capability in “about 10 seconds”:
Glen Herrmannsfeldt wrote:
Here is an awk program that will read in a file line
by line and write the lines out in reverse order. It
will allocate array elements as long as there is still
available memory. Variables are initialized to zero
(or “”), even array elements.
{ array[n++]=$0;}
END {
while(n–>0) print array[n];
}
This took about 10 seconds to write and worked the
first time.
I found this awk snippet in news:comp.lang.fortran this
morning, and it made me realize that I don’t use Ruby as a
*nix filter as often as I probably should because I couldn’t
duplicate the capability in “about 10 seconds”:
[snip]
This took about 10 seconds to write and worked the
first time.
On Thu, May 04, 2006 at 10:22:16PM +0900, Bil K. wrote:
} I found this awk snippet in news:comp.lang.fortran this
} morning, and it made me realize that I don’t use Ruby as a
} *nix filter as often as I probably should because I couldn’t
} duplicate the capability in “about 10 seconds”:
[…]
} { array[n++]=$0;}
}
} END {
} while(n–>0) print array[n];
} }
}
} This took about 10 seconds to write and worked the
} first time.
I have gotten pretty good with Ruby and I can duplicate this in about
10
seconds:
That said, I’d be inclined to do it in awk. (Or I’d use tail -r on
systems
that support it, but that doesn’t seem to include the GNU tools on
Linux.)
Ultimately, use the best tool for the job. If it’s a short script in awk
and that’s what comes to mind, use awk. If you find yourself jumping
through hoops working it out in awk, you’ll probably have better success
in
Ruby. If you find yourself trying Perl before Ruby, however, seek
psychiatric help immediately