in reply to Command line to array

Ok, I've got more to add, sorry folks. $previous_writeup =~ s/Command line/STDIN/gi; Ok, here's some new and (hopefully) inmproved writeup material.

I want to be able to run

table({rows => '2'}, "Cell 1", "Cell", "Blah, blah");
as
prompt:) table {rows => '2'}, "Cell 1", "Cell", "Blah, blah"
But I want to be able to do that with any subroutine. Examples of params could be as follows
[ [ "Blah", "Blah" ], [ "Blah", "Blah" ] ] "Blah, Blah, Blah" [ [ "Baz", [ { Wow => "that's Nesting" }, "Bar" ], "foo" ], [ "More", "Too lazy to be creative", "More here" ] ]
I hope that this make sense. Thank you for excusing my stupity today.

- p u n k k i d
"Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

Replies are listed 'Best First'.
Re: Re: Command line to array
by hdp (Beadle) on Apr 26, 2001 at 04:42 UTC
    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.