in reply to Just Another Thread Hacker

I've taken the liberty to change the code making sure it always returns "Just Another Perl hacker":
use threads;use IO::Socket;@thread=map threads ->create(fetch,$_),9655,6352,297065,138903; print$_->join for@thread;print $/;sub fetch{ $sock=IO::Socket::INET->new(qw(PeerAddr perlmonks.org PeerPort 80));print$sock "GET /?node_id=$_[0]&displaytype=xml HTTP/1.0 \n";local$/;(<$sock>=~/title="(\w+\s)/)}

Liz

Replies are listed 'Best First'.
Re: Re: Just Another Thread Hacker
by davido (Cardinal) on Oct 09, 2003 at 06:17 UTC
    While we're at it... golfed down from liz's 301 keystrokes to 278. Could have gone smaller but a few strokes were added here and there for asthetic purposes, to keep rows nice and tidy.

    use threads;;;use IO::Socket;;;@t=map threads->create(sub{$o= IO::Socket::INET->new(qw(PeerAddr perlmonks.org PeerPort 80)) ;print $o "GET /?node_id=$_[0]&displaytype=xml HTTP/1.0\n\n"; local$/;(<$o>=~/title="(\w+\s)/)},$_),9655,6352,297065,138903 ;print$_->join for@t;print$/
    I lost five strokes in the beautification. ;) The biggest gain was in making the sub an anonymous inline sub rather than a named one.

    Great japh. I always like these ones that grab things off the net.


    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein
      Well, if we're golfing...
      use threads;use IO'Socket;print$_->join for map threads-> create(sub{$o=IO'Socket'INET->new('perlmonks.org:80');print$o "GET /?node_id=$_[0]\n\n";local$/;<$o>=~/e>(\w+\s)/},$_),9655 ,6352,297065,138903;print$/
      A wee bit slower (it grabs the full HTML) and not as prettily formatted, but comes in at 207.

      Toodle-pip,
      Ben