Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Don't re-read file for each new pattern...

by Util (Priest)
on May 30, 2007 at 14:39 UTC ( [id://618195]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    while (1) {
       print 'Please enter a word: ';
    ...
       last if $word =~ /^\s*$/;
       print "You entered '$word'\n";
    }
    
  2. or download this
    # Had to duplicate the prompt, <read>, and chomp.
    # Duplication is bad!
    ...
       print 'Please enter a word: ';
       chomp($word = <STDIN>);
    }
    
  3. or download this
    # Had to add `not defined $word` to handle the special case
    # during the first time through the loop. Very Ugly!
    ...
           print "You entered '$word'\n";
       }
    }
    
  4. or download this
    # Instead of using `not defined $word`, I force
    # non-whitespace into $word.
    ...
           print "You entered '$word'\n";
       }
    }
    
  5. or download this
    # Still had to duplicate code `$word !~ /^\s*$/`
    my $word;
    ...
           print "You entered '$word'\n";
       }
    } while $word !~ /^\s*$/;
    
  6. or download this
    sub prompt {
        my ($prompt_string) = @_;
    ...
    while ( my $word = prompt('Please enter a word: ') ) {
        print "You entered '$word'\n";
    }
    
  7. or download this
    use IO::Prompt;
    while (my $word=prompt 'Please enter a word: ', -while => qr/\S/) {
        print "You entered '$word'\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://618195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found