baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi, well i don't know what is called what i'm asking for because im not coming form informatic background so the terminology is something i'm fighting continuosly with

so here is the deal.

i would like to create some kind of interface in cmd window, something like, for example:

let say i would like to create a set of 5 commands (like print, shift calculate coordinate... something like print, while... in perl). so when i run my script something like vi editor would pop up and i could write

-- > shift "something" while "something else" print "every other character" and coordinate "character"(enter)

my question is what is something like this called and where would i find some more topics about the subject

sorry for being so unclear

as soon as i find out , i'll change the title

once more sorry , personally i also like when things are rightly structured an placed.

Replies are listed 'Best First'.
Re: i will change the title once i now what i'm asking for
by zentara (Cardinal) on Aug 19, 2008 at 17:38 UTC
    The first thing that comes to mind are Dialog boxes from the various GUI's. Each GUI has it's own Dialog code but it's all similar. If you are working from a non-X commandline, there is Curses. Here is a simple Tk Dialog

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: i will change the title once i now what i'm asking for
by psini (Deacon) on Aug 19, 2008 at 18:37 UTC

    ++ for the effort.

    In my opinion what you want to do is something like a command interpreter: an interactive environment inside which you can write a command and get some action/calculation done.

    If this is the case, the first thing you need is defining the syntax of the acceptable commands, next you need a parser to interpret and validate each command and then comes the business logic that make the actions.

    Is this sounding like what you were searching for?

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

      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..

        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

        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" }; };

        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."

Re: command interpreter
by jethro (Monsignor) on Aug 19, 2008 at 20:49 UTC

    A simple shell can be done with perls eval. You only need to create subroutines that do what you want to do. The big plus is you get the power of perl for free with that

    a really trivial example to show what I mean:

    #!/usr/bin/perl use warnings; use strict; sub coordinate { print '<'.join("><",@_),">\n"; } while (<>) { no strict; eval $_; }

    Now you can do this:

    > ./t7.pl coordinate 4 <4> coordinate "test","west","best" <test><west><best> $n=4 coordinate $n <4>
Re: i will change the title once i now what i'm asking for
by jethro (Monsignor) on Aug 19, 2008 at 17:59 UTC

    Only one reply to your question in one hour seems to indicate that I am not alone with my problem understanding your question

    Maybe if you provide two concrete examples of what you want to do with this (without using the word 'something' ;-) ), more monks might be able to give more specific help.

Re: command interpreter
by repellent (Priest) on Aug 20, 2008 at 02:47 UTC
    I stumbled upon code pl.pl in BrowserUk's scratchpad and have modified it since:
    End your input with either ;; to eval() or ;;; to system() it out.

    You may also want to look at: perl -de ''