in reply to Re: Perl subroutine
in thread Perl subroutine update

yes that is supposed to match for example the letter C of the deck of cards and switch it with Clubs so when you printout the deck you get for example 7 Clubs instead of 7C.

Replies are listed 'Best First'.
Re^3: Perl subroutine
by johngg (Canon) on Apr 01, 2011 at 12:12 UTC

    It doesn't though, because you are doing the substitution four times on each element, thus introducing a nice echo effect.

    knoppix@Microknoppix:~$ perl -Mstrict -wE ' > my @pack = > map { > my $suit = $_; > map qq{$_$suit}, qw{ J Q K A }; > } qw{ H C D S }; > my $n = 0; > while ( $n < 4 ) > { > foreach ( @pack ) > { > s/C/Clubs/, s/S/Spades/, s/H/Hearts/, s/D/Diamonds/; > } > $n ++; > } > say qq{@pack};' JHeartseartseartsearts QHeartseartseartsearts KHeartseartseartsearts A +Heartseartseartsearts JClubslubslubslubs QClubslubslubslubs KClubslub +slubslubs AClubslubslubslubs JDiamondsiamondsiamondsiamonds QDiamonds +iamondsiamondsiamonds KDiamondsiamondsiamondsiamonds ADiamondsiamonds +iamondsiamonds JSpadespadespadespades QSpadespadespadespades KSpadesp +adespadespades ASpadespadespadespades knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG