Professional Web Applications Themes

Reading input and Word completion - PERL Beginners

Hi, I'm new to perl and I'm trying to write a simple program that will take commands from user. I would like to provide command completion. Currently I have: use Term::ReadLine; use Term::Complete; while (true) { $mainTerm = Term::ReadLine->new("Top Level"); $OUT = $mainTerm->OUT || *STDOUT; # read command from user $cmd = $mainTerm->readline ('client> '); print $cmds{$cmd}; } I see that it already provides history which is cool! Let's say I have the following commands available at this level - help, exit, do-one, do-two. How do I add this to the program so that when use types h<tab> it completes ...

  1. #1

    Default Reading input and Word completion


    Hi,

    I'm new to perl and I'm trying to write a simple
    program that will take commands from user. I would
    like to provide command completion.

    Currently I have:

    use Term::ReadLine;
    use Term::Complete;

    while (true)
    {
    $mainTerm = Term::ReadLine->new("Top Level");
    $OUT = $mainTerm->OUT || *STDOUT;

    # read command from user
    $cmd = $mainTerm->readline ('client> ');
    print $cmds{$cmd};

    }

    I see that it already provides history which is cool!
    Let's say I have the following commands available at
    this level - help, exit, do-one, do-two. How do I add
    this to the program so that when use types h<tab> it
    completes help and when user doesn't type anything and
    hits <tab> or <ctrl-D> it shows the possible
    completions. Any response is appreciated :)

    Also, can I modify it so that it will take these
    commands from a file or the stdin. I can have an
    option in commandline for reading from file (say, -f
    <fn>). I know how to do the commandline arguments,
    etc.

    thanks,
    manish



    _______________________________
    Do you Yahoo!?
    Shop for Back-to-School deals on Yahoo! Shopping.
    http://shopping./backtoschool
    Manish Guest

  2. #2

    Default Re: Reading input and Word completion

    Hi,

    I was wondering if this is the wrong list for this. Or is the description too vague?

    Any help is appreciated.

    thanks,
    manish

    Manish <com> wrote:

    Hi,

    I'm new to perl and I'm trying to write a simple
    program that will take commands from user. I would
    like to provide command completion.

    Currently I have:

    use Term::ReadLine;
    use Term::Complete;

    while (true)
    {
    $mainTerm = Term::ReadLine->new("Top Level");
    $OUT = $mainTerm->OUT || *STDOUT;

    # read command from user
    $cmd = $mainTerm->readline ('client> ');
    print $cmds{$cmd};

    }

    I see that it already provides history which is cool!
    Let's say I have the following commands available at
    this level - help, exit, do-one, do-two. How do I add
    this to the program so that when use types h it
    completes help and when user doesn't type anything and
    hits or it shows the possible
    completions. Any response is appreciated :)

    Also, can I modify it so that it will take these
    commands from a file or the stdin. I can have an
    option in commandline for reading from file (say, -f
    ). I know how to do the commandline arguments,
    etc.

    thanks,
    manish



    _______________________________
    Do you Yahoo!?
    Shop for Back-to-School deals on Yahoo! Shopping.
    http://shopping./backtoschool

    --
    To unsubscribe, e-mail: org
    For additional commands, e-mail: org




    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.
    Manish Guest

  3. #3

    Default RE: Reading input and Word completion

    Manish wrote: 

    Your example doesn't show evidence that you've read the docs for
    Term::Complete. Start there.
    Bob Guest

  4. #4

    Default RE: Reading input and Word completion


    Hi Bob,

    Thanks for the response. Perhaps someone can point me
    to "docs for Term::Complete". I looked at
    http://www.perl.com/doc/manual/html/lib/Term/Complete.html
    but it wasn't helpful :( It's very brief and when I
    follow what it says I get the following error:

    Undefined subroutine &main::complete called at try.pl
    line 14.

    Any pointers to docs are appreciated.

    thanks,
    manish

    --- Bob Showalter <com>
    wrote:
     
    > this. Or is the 
    >
    > Your example doesn't show evidence that you've read
    > the docs for
    > Term::Complete. Start there.
    >
    > --
    > To unsubscribe, e-mail:
    > org
    > For additional commands, e-mail:
    > org
    > <http://learn.perl.org/>
    > <http://learn.perl.org/first-response>
    >
    >
    >[/ref]




    _______________________________
    Do you Yahoo!?
    Declare Yourself - Register online to vote today!
    http://vote.
    Manish Guest

  5. #5

    Default RE: Reading input and Word completion

    On Mon, 13 Sep 2004, Manish wrote:
     

    We have no way of knowing what you have on line 14.

    The standard perldoc doentation is, admittedly, thin in this case.
    However, if you search for 'perl term::complete' on Google, I see at
    least a couple of more substantive hits within the first dozen returned.

    Please read over the doentation you can find, then write a brief
    script to try it out. If your script fails, sent that brief script back
    to the list along with any error messages you get back.


    --
    Chris Devers
    Chris Guest

  6. #6

    Default Re: Reading input and Word completion

    On Sep 14, 2004, at 12:15 AM, Manish wrote:
     

    Never used this module, but when I get this kind of
    error is because I haven't load functions in the 'rigth' way...

    Try to use this syntax when you load the module:

    use Term::Complete qw(complete);


    HTH

    Remo

    Remo Guest

  7. #7

    Default Re: Reading input and Word completion

    On Tue, 14 Sep 2004, Remo Sanges wrote:
     
    >
    > Never used this module, but when I get this kind of
    > error is because I haven't load functions in the 'rigth' way...
    >
    > Try to use this syntax when you load the module:
    >
    > use Term::Complete qw(complete);[/ref]

    Looking over the available doentation, it seems that Term::Complete
    exports exactly one function: "Complete([prompt], [completion_list)".

    Therefore, there shouldn't be any need to specify the function that is
    being imported, as there is only one function to import.

    That that, it seems, could be the problem: the function provides
    "Complete", with a capital "C". This error refers to "complete", with a
    lowercase "c". Fixing the case may resolve the problem.


    --
    Chris Devers
    Chris Guest

  8. #8

    Default Thanks (was -> Re: Reading input and Word completion)


    Hi Chris,

    Thanks for pointing out the case! The page I was
    looling at doented this as lowercase "complete".
    However I see that some other manpages have the
    correct version - "Complete". Fixing the case does
    the job. Thanks much for pointing this out.

    best regards,
    manish

    --- Chris Devers <com> wrote:
     [/ref]
    > try.pl 
    > >
    > > Never used this module, but when I get this kind[/ref]
    > of 
    > 'rigth' way... 
    >
    > Looking over the available doentation, it seems
    > that Term::Complete
    > exports exactly one function: "Complete([prompt],
    > [completion_list)".
    >
    > Therefore, there shouldn't be any need to specify
    > the function that is
    > being imported, as there is only one function to
    > import.
    >
    > That that, it seems, could be the problem: the
    > function provides
    > "Complete", with a capital "C". This error refers to
    > "complete", with a
    > lowercase "c". Fixing the case may resolve the
    > problem.
    >
    >
    > --
    > Chris Devers
    >
    > --
    > To unsubscribe, e-mail:
    > org
    > For additional commands, e-mail:
    > org
    > <http://learn.perl.org/>
    > <http://learn.perl.org/first-response>
    >
    >
    >[/ref]




    __________________________________
    Do you Yahoo!?
    Yahoo! Mail - 50x more storage than other providers!
    http://promotions./new_mail
    Manish Guest

Similar Threads

  1. #39188 [NEW]: reading php://input hangs with IIS
    By php at nineberry dot de in forum PHP Bugs
    Replies: 4
    Last Post: October 23rd, 05:26 AM
  2. #24028 [Com]: Reading raw post message by php://input
    By vikisain at yahoo dot com in forum PHP Development
    Replies: 20
    Last Post: March 5th, 07:07 PM
  3. Question about reading input file
    By IAMPsycho webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 27th, 05:44 PM
  4. reading the input type=file tag with ie6 in asp
    By Joel Goldstick in forum ASP
    Replies: 1
    Last Post: September 25th, 10:49 PM
  5. Reading from piped standard input on w2k
    By Yuri Shtil in forum PERL Miscellaneous
    Replies: 1
    Last Post: June 30th, 10:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139