Member Avatar for HTMLperson5

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.

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;
}
Member Avatar for HTMLperson5

Thanks 2teez,

Really helped :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.