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

Hello

Been stuck on this for quite awhile and cannot find anything on this. Hope you guys can help, or send me in the right direction.

I have the code below. But i want to do different actions, probably call some subroutines, depending on the escape sequence. At the moment its a cntrl + A. But how would i have several different exit sequences and then carry out some task depending on what was pressed.

e.g. cntrl + T is pressed run "&t_stuff", cntrl + Q runs "&q_stuff"

while($exp){ $exp->interact(\*STDIN,"\cA"); print "you exited"; }

Something like this....

while($exp){ $exp->interact(\*STDIN,"\cA"); if("escape sequence capture" =~ /\cT/){ &t_stuff; }else{ print "you exited"; } }

Replies are listed 'Best First'.
Re: Using interact()
by InfiniteSilence (Curate) on May 14, 2014 at 20:02 UTC

    Hmmm...it is not obvious according to the pod but there is a method in the code that looks like it does this, set_seq. The comment at the head of the code reads:

    # Set an escape sequence/function combo for a read handle for intercon +nect. # Ex: $read_handle->set_seq('',\&function,\@parameters);

    I found this after noticing that the interact appears to be looping over some structure. You can set debugging on in the following way. It might help:

    use Expect; $Expect::Log_Stdout=1; $Expect::Debug=3; $Expect::Exp_Internal=1; ...

    Celebrate Intellectual Diversity

Re: Using interact()
by Laurent_R (Canon) on May 14, 2014 at 20:41 UTC
    Hum, not sure I understood what you are looking for, but a dispatch table (i.e. generally a hash in which you store code references to subroutines to be executed for the various possible inputs) might something useful for you.
Re: Using interact()
by oldirtysingh (Novice) on May 14, 2014 at 21:04 UTC
    Well i just want to capture the escape sequence in an interact function. In variable or anything.