We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,725 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

problem with Perl command line - File handling

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' ) {
            ...
1
Contributor
1
Reply
26 Minutes
Discussion Span
4 Months Ago
Last Updated
3
Views
Question
Answered
rogerg
Light Poster
31 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

solved, thx

rogerg
Light Poster
31 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 4 Months Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5141 seconds using 2.65MB