[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shell Golf
On Thu, May 08, 2003 at 12:58:44AM -0500, Steven Pritchard wrote:
> Not as short, but a heck of a lot more efficient:
>
> perl -e 'while(<>){$x=length$_;@n=($x,$ARGV,$_)if$x>$n[0]}print"@n"' *.pl
After a bit more thought, I can do better (shorter anyway) than that. :-)
perl -ne '$x=length;@n=($x,$ARGV,$_)if$x>$n[0];END{print"@n"}' *.pl
And for all the non-perl geeks out there, that's equivalent to this:
while ($line=<>) {
$length = length($line);
if ($length > $longest[0]) {
@longest = ($length, $ARGV, $line);
}
}
print "@longest";
(Hopefully that makes a tiny bit more sense.)
Steve
--
steve@silug.org | Southern Illinois Linux Users Group
(618)398-7360 | See web site for meeting details.
Steven Pritchard | http://www.silug.org/
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.