#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Basic Perl Program Help


    Can someone help me determine how to convert the text entered in <STDIN> to lowercase so that however the user enters 'heads' or 'tails', the block executes? Here is what I have so far:

    #!/usr/bin/perl -w

    print "Please type in either heads or tails: ";

    # The <STDIN> is the way to read keyboard input

    $answer = <STDIN>;
    chomp $answer;

    while ( $answer ne "heads" and $answer ne "tails" ) {
    print "I asked you to type heads or tails. Please do so: ";
    $answer = <STDIN>;
    chomp $answer;
    }

    print "Thanks. You chose $answer.\n";
    print "Hit enter key to continue: ";

    # This line is here to pause the script until you hit the
    # carriage return
    # The input is never used for anything.

    $_ = <STDIN>;

    if ( $answer eq "heads" ) {
    print "HEADS! you WON!\n";
    } else {
    print "TAILS?! you lost. Try again!\n";
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    The lc function returns a lower case version of the expression passed to it.

    Perl Code:
    my $lc_string = lc "FOOBAR"; #  $lc_string now contains "foobar"
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    Thank you!!!

IMN logo majestic logo threadwatch logo seochat tools logo