BEGIN { my @levels = ( initiate => 1, novice => 20, acolyte => 50, scribe => 100, monk => 200, friar => 500, abbot => 1000, bishop => 1600, pontiff => 2300, saint => 3000 ); while ( @levels ) { my ( $level, $xp ) = splice @levels, 0, 2; eval "sub $level () { $xp }"; } } $xp = 0 + shift; printf "XP = $xp %0.2f initiates %0.2f novices, %d to promotion %0.2f acolytes, %d to promotion %0.2f scribes, %d to promotion %0.2f monks, %d to promotion %0.2f friars, %d to promotion %0.2f abbots, %d to promotion %0.2f bishops, %d to promotion %0.2f pontiffs, %d to promotion %.02f saints, %d to promotion ", $xp / initiate, $xp / novice, novice - ( $xp % novice ), $xp / acolyte, acolyte - ( $xp % acolyte ), $xp / scribe, scribe - ( $xp % scribe ), $xp / monk, monk - ( $xp % monk ), $xp / friar, friar - ( $xp % friar ), $xp / abbot, abbot - ( $xp % abbot ), $xp / bishop, bishop - ( $xp % bishop ), $xp / pontiff, pontiff - ( $xp % pontiff ), $xp / saint, saint - ( $xp % saint ); # I wish this was lisp. for ( qw( saint pontiff bishop abbot friar monk scribe acolyte novice +initiate ) ) { eval "if ( \$xp >= $_ ) { push \@change, int( \$xp / $_ ) . \" ${_ +}s\"; \$xp %= $_ }"; } for ( @change ) { if ( 1 == $_ ) { s/s$//; } } $_ = join( ', ', @change, ) . "\n"; # Replaced w/ NinthWave's code. No, I didn't read it first. s<(?:^|\D)(1 [a-z]+(?:, 1 [a-z]+)*)>{ my @ranks = $1 =~ /[a-z]+/g; " a " . join ', ', @ranks; }ge; s/^ //; if ( /,.+,/ ) { s/(.+),([^,]+)/$1, and$2/; } print

In reply to Making XP Change by diotalevi

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.