Here’s a very simple one-liner REPL for perl, it’s not very advanced (like ie. re.pl) but does well in most cases:
perl -MData::Dumper -MTerm::ReadLine -e '$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("code: "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'
It uses Term::ReadLine, which gives a simple session history if you have a Term::ReadLine::* implementation that supports it. It will also use Data::Dumper so that you can quickly see any data structures, you can always use scalar(STATEMENT) if the return value differs in list and scalar context.
Here’s an alias that can be shoved into .bashrc :
alias 'perl-repl'='perl -MData::Dumper -MTerm::ReadLine -e '\''$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("code: "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'\'''
| This entry was posted on Tuesday, March 2nd, 2010 at 15:42 and is filed under Random. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. |