Playing cards: Difference between revisions

m
→‎{{header|Perl}}: future-proof for 5.36
(Playing cards in Yabasic)
m (→‎{{header|Perl}}: future-proof for 5.36)
Line 4,732:
 
use strict;
use warnings;
 
@Playing_Card_Deck::suits = qw
Line 4,747 ⟶ 4,748:
{my $invocant = shift;
my $class = ref($invocant) || $invocant;
my @cards = ();
foreach my $suit (@Playing_Card_Deck::suits)
{foreach my $pip (@Playing_Card_Deck::pips)
Line 4,756 ⟶ 4,757:
# Removes the top card of the given deck and returns it as a hash
# with the keys "suit" and "pip".
{return %{ shift( @{shift(@_)} ) };}
 
sub shuffle
Line 4,770 ⟶ 4,771:
sub print_cards
# Prints out a description of every card in the deck, in order.
{print "$_->{pip} of $_->{suit}\n" foreach @{shift(@_)};}</syntaxhighlight>
Some examples of use:
<syntaxhighlight lang="perl">my $deck = new Playing_Card_Deck->new;
$deck->shuffle;
my %card = $deck->deal;
2,392

edits