#!/usr/bin/perl # Shuffles cards @pack = (1, 2, 3, 4, 5, 6, 7, 8); sub b { push(@pack, shift @pack); } sub i { my ($a, $b, $c, $d, $e, $f, $g, $h) = @pack; @pack = ($e, $a, $f, $b, $g, $c, $h, $d); } sub o { my ($a, $b, $c, $d, $e, $f, $g, $h) = @pack; @pack = ($a, $e, $b, $f, $c, $g, $d, $h); } sub parse { my ($string) = @_; print "\nParse $string: "; foreach $offset (0..(length($string)-1)) { $char = substr($string, $offset, 1); if ($char =~ /b|i|o/) { print "bio "; &{$char}; } elsif ($char =~ /\d/) { print "digit "; # foreach (1..$char) { &parse(substr($string, $offset+1)); } } elsif ($char =~ /\(/) { print "open "; &parse(substr($string, $offset+1, (rindex($string, ")", $offset)-$offset)+1) ); } elsif ($char eq ")") { print "close "; } } } chomp($shuffle = ); &parse($shuffle); print "\n@pack\n";# #### oib(oib) Parse oib(oib): bio bio bio open Parse o: bio bio bio bio close 1 4 5 8 2 3 6 7 #### oib(oib) Parse oib(oib): bio bio bio open Parse oib: bio bio bio # whatever here