in reply to Re: i will change the title once i now what i'm asking for
in thread command interpreter

Yes, this sounds like it, so, where can i read more about it ? how can i create something like that (i'm not looking for the exact "how to do "

THANKS

update: quick look through google gives an impression that this is not something easy to do... cr..

Replies are listed 'Best First'.
Re^2: command interpreter
by zentara (Cardinal) on Aug 19, 2008 at 19:23 UTC
    This is how you might do it. At least it's a start. When you read the results from your commands, do whatever you want depending on the returned text. I think what you really need to do here, is substitute /bin/bash with your script, 'myprocessor.pl'. Then, have myprocessor.pl accept commands on stdin, run appropriate subs, and return answers.
    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; use IO::Select; my $pid = open3(\*WRITE, \*READ,\*ERROR,"/bin/bash"); my $sel = new IO::Select(); $sel->add(\*READ); $sel->add(\*ERROR); my($error,$answer)=('',''); while(1){ print "Enter command\n"; chomp(my $query = <STDIN>); #send query to bash print WRITE "$query\n"; foreach my $h ($sel->can_read) { my $buf = ''; if ($h eq \*ERROR) { sysread(ERROR,$buf,4096); if($buf){print "ERROR-> $buf\n"} } else { sysread(READ,$buf,4096); if($buf){print "$query = $buf\n"} } } } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re^2: command interpreter
by Corion (Patriarch) on Aug 19, 2008 at 21:05 UTC

    The easy way to fake a command interpreter is to reuse an existing command interpreter. The one command interpreter you have at hand is Perl, and Perl has the eval statement, which gives you the whole Perl interpreter to use.

    So one approach would be to take your command language and convert it into a Perl program. If you give your command language enough thought beforehand, this can be done by something as simple as Filter::Simple, just like Querylet does, or maybe Filter::QuasiQuote, if you don't mind the wrapper of your program looking like Perl.

    The following is a simple interpreter for arithmetic expressions, as long as they are on one line:

    use strict; while (<>) { my $res = eval $_; if (my $err = $@) { warn "Error: $@"; } else { print "'$_' gives $res\n" }; };
Re^3: i will change the title once i now what i'm asking for
by psini (Deacon) on Aug 19, 2008 at 19:28 UTC

    Well, for a start you could change the node title :-)

    Seriously, I don't know where you could start from:

    "defining a syntax" can be a big job if you want a language with a minimum of flexibility, or a trivial one if you have only a handful of commands to implement. It really depends on what your program should do, and you have not given much detail.

    On the parser side, there are many choices available but I never did these things in Perl, so it's better for somebody else to advise you.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."