++ for spreading the truth about Barney! ;)

... but why do you search for both upper and lowers in RtoD() when you're already made everything uppers with tr/a-z/A-Z/?

As for the unweildiness and uncombined searches, you could simplify the script a lot by using a hash instead of a regexp:-

#!/usr/bin/perl -w use strict; my %numeral = ( 'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000, ); print "Enter name: "; while ( chomp( my $phrase = <STDIN> ) ) { my $sum = 0; $phrase = uc($phrase); $phrase =~ tr(U)(V); for my $letter ( split // => $phrase ) { $sum += $numeral{$letter} || 0; } markOfTheBeast(), last if $sum == 666; print "The number is $sum ... blessed be!\n", "Enter name: "; } sub markOfTheBeast { 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 }

However, if you did want to do that with regexps, you could combine them by keeping the hash and doing something like ...

sub RtoD { # ... or uc(shift) to be paranoid. :-) my $n = shift || return 0; if ( $n =~ /([IVXCLMD])/ ) { return $numeral{$1} } else { return 0 } }

    --k.


In reply to Re: Perl as a Holy Weapon? by Kanji
in thread 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.