Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL - pressEnter function hanging 1

Status
Not open for further replies.

chris01010

Programmer
Jan 29, 2004
25
0
0
GB
Hi,



I have a sub function called pressEnter within my perl menu script which basically means that the script will await an interaction from the user before moving on.



Unfortunately when the script goes into pressEnter it just hangs (even if you press enter!!).



Any ideas on what could be causing this?



Code:
sub checkJob

{

system('clear');

print "The current Job Status is:\n\n";

      `./scriptlist.ksh 2`;

      open OUTPUT, "./output";

      undef $/;

      $_ = <OUTPUT>;

      ($var) = m/^(INTE.*PM)$/sm;

      print "$var\n\n";

      close OUTPUT;

      pressEnter();

    }

sub pressEnter

{

print "Press Return to continue\n\n";

      $dummy = <>;

      mainMenu();

}



I've included another sub function so you can see how it is called.
 
I might suggest explicitly stating you want to read from STDIN and see if it fixes the problem:

Code:
$dummy = <[red][b]STDIN[/b][/red]>;
 
thanks for the suggestion, but it still hangs. I can keep pressing enter and all it does is line feed down the terminal instead of returning to the main menu.
 
I should have looked closer. It's because you're undef'ing the input record separator ($/) - normally that's set to enter, now it's undef, so hitting the enter key doesn't signify the end of a line any more.

Probably the easiest way to fix this, based on the code you posted, is something like the following:
Code:
print "The current Job Status is:\n\n";
`./scriptlist.ksh 2`;
open OUTPUT, "./output";
#undef $/;
{
    local $/ = undef;
    $_ = <OUTPUT>;
}
That way, $/ is returned to it's previous value as soon as you exit that block of code.
 
Of course!! Brilliant, makes perfect sense.

Thanks.
 
Hi

Good catch, rharsh. [medal] I completely missed that [tt]undef[/tt].


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top