theclapp

Search theclapp.blog-city.com

 

What might a sexpr-based Perl look like?

posted Saturday, 14-Apr-2007
My Perl remote-agent had this code in it:
sub run_program {
my ($id, @args) = @_;
my $cmd = join( " ", @args );
open( CHILD, "$cmd 2>&1 |" )
or die "Couldn't open pipe from $cmd: $!";
my $input = "";
while (sysread( CHILD, $input, $BLOCK_SIZE )) {
syswrite( STDOUT, $id . "," . length( $input ) . "\n" . $input ) ;
}
syswrite( STDOUT, "$id,0\n" );
close( CHILD ); # fixme: ignores child exit code
}
I mused on what it might look like as s-expressions.
(sub run_program
(= (my ($id @args)) @_)
(= (my $cmd) (join " " @args))
(or (open CHILD "$cmd 2>&1 |")
(die "Couldn't open pipe from $cmd: $!"))
(= (my $input) "")
(while (sysread CHILD $input $BLOCK_SIZE)
(syswrite STDOUT (. $id "," (length $input) "\n" $input)))
(syswrite STDOUT "$id,0\n")
(close CHILD))
Not much better. :)

tags:    

links: digg this    del.icio.us    technorati    reddit