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

Re: Shell Golf



I should point out that I started typing my response with pretty much 
this solution at about 8:30 this morning and hit "send" about 5 seconds 
before my mail program grabbed this message. :(

Curse you, Steve. :)

--Danny, trying to save a little face, anyway

Steven Pritchard wrote:

> 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


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