in reply to Re: P2P Golf: MoleSter
in thread P2P Golf: MoleSter
The author is working on revamping the while() loop and moving to use read() instead of <> for the socket. But, I don't have that version, so I'll work with what I have.
sub f{for$w(keys%k){&t}}$/=$_;($,,$w=$a,%k)=splice@ARGV,0,3;socket S,2 +,1,6;bind S,&a;sub i{$k{$w}=1}sub a{$w=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub +t{socket X,2,1,6;if(connect X,a){print X "$, $_[0] $_[1]/$_[2]";close}else{dele +te$k{$w}}} listen S,5;while(@ARGV&&($_="$, $a f".shift)||accept(C,S)&&($_=<C>)&&c +lose){ m!(\S*) ([e-i])([^/]*)/!s&&$,eq$`&&&$2($w=$1,$3,$')}sub e{open F,'>',$ +3;print F $';close}sub g{open(F,'<',$3)&&t$a,"e$3", <F>;close F}sub h{t$_,i for +keys%k}
This code is sooo completely untested. :-) The readable version ...
sub f{ for$w(keys%k){&t} } $/=$_; ($,,$w=$a,%k)=splice@ARGV,0,3; socket S,2,1,6; bind S,&a; sub i{ $k{$w}=1 } sub a{ $w=~/:/; pack'CxnC4x8',2,$',split'\.',$` } sub t{ socket X,2,1,6; if(connect X,a){ print X "$, $_[0] $_[1]/$_[2]"; close }else{ delete$k{$w} } } listen S,5; while(@ARGV&&($_="$, $a f".shift)||accept(C,S)&&($_=<C>)&&close){ m!(\S*) ([e-i])([^/]*)/!s&&$,eq$`&&&$2($w=$1,$3,$') } sub e{ open F,'>',$3; print F $'; close } sub g{ open(F,'<',$3)&&t$a,"e$3", <F>; close F } sub h{ t$_,i for keys%k }
Update: After jonadab's suggestions and some reorganization, we save 11 characters (down to 459 over 6 lines):
sub f{for$w(keys%k){&t}}$/=$_;($,,$w=$a,%k)=splice@ARGV,0,3;socket S,2 +,1,6;bind S,&a;sub i{$k{$w}=1}sub a{$w=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub +t{socket X,2,1,6;connect(X,a)?print(X "$, $_[0] $_[1]/$_[2]")&&close:delete$k{$ +w}}listen S,5;while(@ARGV&&($_="$, $a f".shift)||accept(C,S)&&($_=<C>)&&close){s +ub h{t$_,i for keys%k}m!(\S*) ([e-i])([^/]*)/!s&&$,eq$`&&&$2($w=$1,$3,$')}sub e{o +pen F,'>',$3;print F $';close}sub g{open(F,'<',$3)&&t$a,"e$3",<F>;close F} }
Yes, there's a subroutine definition in the while-loop. "perl -MO=Deparse" tells me it's ok.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: P2P Golf: MoleSter
by jonadab (Parson) on Dec 17, 2004 at 15:16 UTC | |
by dragonchild (Archbishop) on Dec 17, 2004 at 15:57 UTC | |
by jonadab (Parson) on Dec 23, 2004 at 22:58 UTC |