0

How can you get an if statement in another if, for instance:

$line = <STDIN>;
if $line eq "\n") {
print "You did not type anything
} else {
print "You said: $line";
}

Could you put anotherifnext to the place where it says:

You said: blah

like this:

You said: blah, are you sure?(y/n)

and then the user must type y or n for the program to continue.

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by HTMLperson5
1

Hi HTMLperson5,

Could you put anotherifnext to the place where it says:

You said: blah

like this:

You said: blah, are you sure?(y/n)

and then the user must type y or n for the program to continue.

why not?
See the script below for what you want to do. I suppose.

#!/usr/bin/perl
use warnings;
use strict;

my $line = "";

INTER: {
do {
    print "What do you say?: ";
    $line = qna();
    if ( $line =~ /^$/ ) {
        print "You did not type anything", $/;
    }
    else {
        print "You said: ", $line, ". Are you Sure? (y/n):";
        my $ans = qna();
        if ( $ans eq 'y' ) {
            print "Yes, I said, ", $line, $/;
            last;
        }
        else { print "Nope, I said Uhhmmm...", $/; redo INTER; }
    }
  }
}

sub qna {
  chomp( my $line = <STDIN> );
    return $line;
}
0

Thanks 2teez,

Really helped :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.