How can I call a module in a Perl one-liner?

Posted by Zaid on Stack Overflow See other posts from Stack Overflow or by Zaid
Published on 2010-04-08T13:39:21Z Indexed on 2010/04/08 13:53 UTC
Read the original article Hit count: 333

Filed under:
|
|
|

Say I have a data file that I want to process; I want to take the maximum value of each of the column and append it to the end of each line.

INPUT:

T1 T2 T3
35.82 34.67 31.68
32.20 34.52 33.59
37.41 38.64 37.56

OUTPUT:

T1 T2 T3
35.82 34.67 31.68 35.82
32.20 34.52 33.59 34.52
37.41 38.64 37.56 38.64

I'm trying to implement this as a one-liner. So far, this is what I've come up with, although it complains that &main::max is undefined:

perl -MList::Util -ani.bak -e "print qq(@F).q( ).max(@F).qq(\n)" file1.txt

It seems that I haven't loaded the List::Util module. What's wrong? And is the header column an issue?

perlrun doesn't have a decent example on how to do this (actually it does now, my documentation was a little out-of-date).

© Stack Overflow or respective owner

Related posts about perl

Related posts about one-liner