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

Hi, I need to navigate a text based menu with using Net::Telnet module, capture the out put into a file and parse it. In the menu based navigation after the selection of first 2 hirercies .....when i send a key for next menu navigation ....the module seems to myterious send some "\r" / "\n" ...i can't figure out wher it is picking it from ..... hence causing me the program to navigate to wrong menus selection.... how could this be handled any help/hint is appreciated... also i observed at times the output of a previous selection is sent on subsequent selection at times. i have tried with both input_record_seperator and out_put_record_seperated ...n they haven been of much help. appreciate quick responses
  • Comment on Net::Telnet problems with Net::Telnet in handling inputs

Replies are listed 'Best First'.
Re: Net::Telnet problems with Net::Telnet in handling inputs
by robartes (Priest) on Mar 25, 2003 at 06:39 UTC
    I don't know if this will help you, but have a look at the chomp function to lop off trailing newline characters.
    also i observed at times the output of a previous selection is sent on subsequent selection at times
    Hmm. If you are talking about the menu of a previous key press being sent with a next one, then I'd say this is a buffering issue. Try unbuffering STDOUT:
    select((select STDOUT, $|++)[0]);

    CU
    Robartes-

Re: Net::Telnet problems with Net::Telnet in handling inputs
by castaway (Parson) on Mar 25, 2003 at 12:41 UTC
    From the Net::Telnet doc:
    The output record separator for print() and cmd() is set to "\n" by de +fault, so that you don't have to append all your commands with a newl +ine. To avoid printing a trailing "\n" use put() or set the output_re +cord_separator to "".
    Which means whenever you use 'print' or 'cmd' it will send a newline, whether you wanted one or not.
    Further:
    In the input stream, each sequence of carriage return and line feed (i +.e. "\015\012" or CR LF) is converted to "\n". In the output stream, +each occurrence of "\n" is converted to a sequence of CR LF. See binm +ode() to change the behavior. TCP protocols typically use the ASCII s +equence, carriage return and line feed to designate a newline.
    Eg: All newlines are sent as "\r\n", as that is how Telnet does newlines.

    Maybe you should show some code where you tried changing the output_record_separator, or try using put() ?

    C.