Hello, I have a problem when trying to prompt users on two levels with Perl. The first prompt command works fine. But when doing the second command as below, I get Enter a command (count/close/quit) : Enter a command (open/quit). I don't see right away why this happens. Any idea? Here is the beginning of my code:

#!/usr/bin/perl

# 1st command
print 'Enter a command (open/quit) : ';

ENTER_COMMAND:
while ( defined( $command = <STDIN> ) ) {

    chomp $command;

    if ( $command eq 'quit' ) { last ENTER_COMMAND; }  

    elsif ( $command eq 'open' ) {

        $name = '';

        ENTER_NAME:
        while ( $name eq '' ) {       

            print 'Please enter the filename : ';
            chomp( $name = <STDIN> );
        }

        # If file can be open
        if ( open( $input_file, "$name" ) ) {

            # Read lines of files and affect it to array
            @lines = <$input_file>;

            # 2nd command
            print 'Enter a command (count/close/quit) : ';

            if ( $command eq 'count' ) {
            ...

solved, thx

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.