1,105,456 Community Members

problem with Perl command line - File handling

Member Avatar
rogerg
Light Poster
33 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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' ) {
            ...
Member Avatar
rogerg
Light Poster
33 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

solved, thx

Question Self-Answered as of 1 Year Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: