prompting multiple questions to user (yes/no & file name input)

后端 未结 3 1852
遥遥无期
遥遥无期 2021-02-15 15:43

I want to ask the user multiple questions. I have two types of questions: Y/N or filename input. I\'m not sure how to place this all into a nice if structure. And I

3条回答
  •  梦谈多话
    2021-02-15 16:26

    You can use Sub Routines. This helps you visibly and logically keep everything in-line. for instance

    
        &main();
    
        sub main {
            print "Do you want to import a list(Y/N)";
            my $input = ;
            chomp $input;
            if($input =~ m/^[Y]$/i) {
                &importfile();
            } elsif ($input =~ m/^[N]$/i) {
                print "you said no";
            } else {
               print "Invalid option";
            }
        }
        sub importfile
        {
            print "file name please ";
            my $file = STDIN;
            # import and process the file here.....
            &main();
        } 
    

    So you can import at many files this way.

提交回复
热议问题