[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell Golf

Yes I know it's cheap but:
perl -pe '$_=length()." $ARGV $_"' *.pl|sort -n|tail -1
or if an error msg is okay:

perl -pe '$_=length." $ARGV $_"' *.pl|sort -n|tail -1

54 or 56 depending on if you're allowed to have a warning :P

-----Original Message-----
From: silug-discuss-owner@silug.org
[mailto:silug-discuss-owner@silug.org] On Behalf Of
Sent: Wednesday, May 07, 2003 1:47 PM
To: silug-discuss@silug.org; luci-discuss@luci.org
Subject: Shell Golf

Here's the problem:

We have a directory of full of files, all perl scripts, ending in ".pl".

We want to know the length of the longest line, the file it comes from
and the line itself.

My solution clocks in at a hefty *59* characters. Any contenders?

perl -p -e '$_=length($_)." $ARGV $_"' *.pl|sort -n|tail -1

FYI, the end goal was to determine the minimal sdiff width required to
compare a bunch of files in two directories.



To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.

To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.