I was getting into regular expressions a bit and discovered that Perl has some esoteric qualities that could lend itself to be a powerful tool in the fight against evil. As monks, it is our duty to use Perl as a force for good. Here is a quick and dirty script, with not much flexibility for now to allow automation, but it calculates an interesting number. :) Radagast
#!/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 }
UPDATE: Sorry about the unwieldiness of the code. For example, I'd love to have combined the searches

In reply to Perl as a Holy Weapon? by radagast

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.