UPDATE: Sorry about the unwieldiness of the code. For example, I'd love to have combined the searches#!/usr/bin/perl # Have a little fun. Type a name, let the program extract the Roman # numerals in them, and add them up. The letter V was used instead of # U so that conversion will be done here. # # To verify this works, type CUTE PURPLE DINOSAUR to test it and the n +umber # output will be 666. $name = ""; $strLen = 0; $sum = 0; print "Enter name: "; while (<STDIN>) { chomp; $strLen = length $_; tr/a-z/A-Z/; tr/U/V/; @arr = split //; for ($i = 0; $i < $strLen; $i++) { if ($arr[$i] =~ /I|V|X|L|C|D|M/) { $sum += RtoD($arr[$i]); } } if ($sum == 666) { markOfTheBeast(); last; } else { print "The number is $sum...blessed be!\n"; } $sum = 0; print "Enter name: "; } sub RtoD { $X = shift; if ($X =~ /i|I/) { return 1; } elsif ($X =~ /v|V/) { return 5; } elsif ($X =~ /l|L/) { return 50; } elsif ($X =~ /c|C/) { return 100; } elsif ($X =~ /d|D/) { return 500; } elsif ($X =~ /m|M/) { return 1000; } else { return 0; } } sub markOfTheBeast { system "clear"; print <<END_OF_DAYS ********************************************************************* *YOU HAVE EXPOSED THE SIGN OF THE BEAST. PLEASE REDEEM YOUR GET OUT* * OF HELL FREE CARD AT THE NEAREST STARBUCKS OR PORTAL TO HELL TO * * AVOID THE ONCOMING APOCALYPSE. * ********************************************************************* END_OF_DAYS }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl as a Holy Weapon?
by Kanji (Parson) on Dec 02, 2000 at 20:51 UTC | |
by merlyn (Sage) on Dec 02, 2000 at 21:34 UTC | |
|
Re: Perl as a Holy Weapon?
by belg4mit (Prior) on Dec 07, 2000 at 03:43 UTC | |
by belg4mit (Prior) on Dec 07, 2000 at 04:01 UTC |