Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, the actual code is:
$p=shift;$a=shift;i(shift);socket S,2,1,6;bind S,&a($a);listen S,5;$/=undef;while(@ARGV&&($_="$p $a f".shift)||accept(C,S)&&($_=<C>)& +&close C){m!^(.*?) (.*?) ([e-i])([^/]*)/!s&&$1 eq$p&&&$3($2,$4,$');}sub e{ope +n F,'>',$_[1];print F $_[2];close F}sub f{&s($_,@_)for keys %k}sub g{open(F,'<',$_[1])&&&s($_[0],$a,"e$_[1]",<F>);close F}sub h{&s($_[0],$_,'i')for keys %k}sub i{$k{$_[0]}=1}sub a{$_[0]=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub s{socket X,2,1,6;$w=shift;if(connect X,&a($w)){print X "$p $_[0] $_[1]/$_[2]";close X}else{undef $k{$p}}}
Of course I'm not the one "Who wants to take the first crack at golfing this down" but giving a peek into the first few lines I notice that there's plenty of room for golfing. In fact I'm only a mediocre golfer, but golfers for example generally pop() rather than shift().

Or, for example, C<undef$/;> takes one keystroke less than C<$/=undef;>. But then (e.g.) C<$/=$_> will do and is even shorter.

Again, selecting a randomly picked line, I'm a big fan of the three-arguments form of open(), but C<open(F,'<',$_[1])> can be replaced by C<open F,pop>.

As a side note, since we're talking golf here, well one doesn't generally care much about good programming practices in this context. But the author of the original code's systematic (&-form of) calling of subs clearly tells what his programming skills can be...


In reply to Re: P2P Golf: MoleSter by blazar
in thread P2P Golf: MoleSter by hossman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found