Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Command line to array

by hdp (Beadle)
on Apr 26, 2001 at 04:42 UTC ( [id://75679] : note . print w/replies, xml ) Need Help??


in reply to Re: Command line to array
in thread Command line to array

eval is the easiest way to do this, since you don't end up with your own mini-language to parse; just let perl do it. Here's a very primitive command-line example:
% perl -MData::Dumper -nwe 'chomp; ($sub, $rest) = split / +/, $_, 2; eval "$sub($rest)"; print $@ if $@; print "\n) " } BEGIN { sub spew { print Dumper(@_) } print ") "'
Presumably you'll have more functions defined than that; consider using Term::Readline or similar if this is something that'll be used a lot.

hdp.