Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

check out the class build-up of the following example i once made for a blackjack game, i couldn't find another example. Compare that with yours.

package Bank; our %kaarten = qw/2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 J 10 Q 10 K 10 + A 11/; our @kaarten = keys(%kaarten); our $totaal; our $azen = 0; our $cor; sub new{ $self = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; if($waarde == 11){ $azen +=1;} print "Bank heeft een $kaart. Puntentotaal = $waarde.\n"; $totaal += $waarde; return $self; } sub bankspeel{shift; $inze = shift; $to = shift; $saldo = shift; while($totaal<17){ $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; $totaal += $waarde; print "Bank heeft een $kaart. Puntentotaal = $totaal.\n"; if($totaal > 21){ if($azen != 0){ $cor = 10 * $azen; if(($totaal-$cor)>21){ print "Busted, u wint $inze.\n" } else {$totaal = $totaal - $cor; if($totaal<12){$totaal += 10;}} }} if($totaal > 21){ print "Busted.U wint $inze.\n";$saldo+=$inze;print "Uw saldo is $saldo +\n"; exit; } sleep(2); } if($to > $totaal){print "U wint $inze\n";$saldo+=$inze;print "Uw saldo + is $saldo\n"} elsif($to < $totaal){print "U verliest $inze\n";$saldo-=$inze;print "U +w saldo is $saldo\n"} else{ print "stand-off\n";} } sub kaart{ $self = shift; $tot = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $tot += $waarde; return $tot; } sub double{ shift; $to = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $to+=$waarde; print "U past op $to.\n"; return $to; } 1;

In reply to Re: Problems with passing arguments to a subroutine in a perl package by Anonymous Monk
in thread Problems with passing arguments to a subroutine in a perl package by mmnormyle

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2018-07-21 15:39 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (449 votes). Check out past polls.