Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: BOfH Random Excuse Generator

by virtualsue (Vicar)
on May 26, 2001 at 13:24 UTC ( #83486=note: print w/replies, xml ) Need Help??

in reply to BOfH Random Excuse Generator

This was kinda cute, even though I don't completely understand the deal with DUMMYMODE (in the BOFH mindset, *all* users are dummies, so that should be a design assumption rather than a switch :)). I do have a few suggestions for you:

while (<>) { if ($_ eq /yes/ or /y.*/) { print "\n$word1 $word2 $word3 $word4\n"; exit; } else { exit; } }
Your regex has a little problem. It will match 'y' anywhere in the input, rather than at the beginning of the input string which I think is what you want. Use the ^ assertion to match at the beginning of the string. Also, if you have verified that the user has started his answer with 'y' you don't really need to check explicitly for the string 'yes'.
See also the informative nodes Death to Dot Star! and Do not use diamond for STDIN.
Here's a less-cluttered alternative to your while loop block:
my $ans = <STDIN>; print "\n$word1 $word2 $word3 $word4\n" if ($ans =~ /^y/);
or even:
print "\n$word1 $word2 $word3 $word4\n" if (($ans = <STDIN>) =~ /^y/);

Replies are listed 'Best First'.
Re: Re: BOfH Random Excuse Generator
by mexnix (Pilgrim) on May 27, 2001 at 08:45 UTC
    Thanks for the help. I'm really just starting out with regex's, and I guess I should have remembered the no-no. It's my fault. Always's looking for constructive criticism (what did I just get my self into???).


      Don't worry about it. I ++'d your fine node, and so did a lot of other people. You posted working code that used -w & strict so, you are by definition a Righteous Dude. Everything can be improved, including what I posted.

      For instance,

      print "\n$word1 $word2 $word3 $word4\n" if (($ans = <STDIN>) =~ /^y/); could have been print "\n$word1 $word2 $word3 $word4\n" if (<STDIN> =~ /^y/i); or print "\n$word1 $word2 $word3 $word4\n" if (<STDIN> =~ /^[Yy]/);

      Updated per chromatic's suggestion to allow for case insensitive matching.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83486]
NodeReaper sharpens his wit

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-10-23 07:13 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.