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

I am asking a user for many different <STDIN>, can I have one statement that says if any <STDIN> eq 'exit' end the script? Many Thanks! TW

Replies are listed 'Best First'.
Re: Entering EXIT at any prompt
by FunkyMonk (Bishop) on Feb 07, 2008 at 23:09 UTC
    You can't do as you asked, but you can mimic the behaviour with a subroutine:
    sub input { chomp( my $input = <STDIN> ); exit if $input eq "exit"; return $input; }

    With that sub defined, just use my $var = input(); instead of my $var = <STDIN>;

      Perfect! Thank you!
Re: Entering EXIT at any prompt
by jrsimmon (Hermit) on Feb 07, 2008 at 22:55 UTC
    Without some code, this is only a guess at what you're asking....
    use strict; use warnings; while(my $input = <STDIN>){ die "User requested exit" if $input eq 'exit'; #do whatever... }
Re: Entering EXIT at any prompt
by mhearse (Chaplain) on Feb 08, 2008 at 06:20 UTC