CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Sub Routine Question


New User

Aug 31, 2009, 7:49 PM

Post #1 of 2 (343 views)
Sub Routine Question Can't Post

Hello, I'm new to this forum as well as the PERL language and just found this forum on so I'm testing it out. Anyways, I been learning PERL on and off for about 3 weeks and just decided to start making a Ceelo game program to put some skills to work and gain some experience. Simple program no graphics or anything like that. The piece of code I would like looked at or critiqued for better or more efficient ways of writing is a sub routine in the program. It recognizes when a 4-5-6 in all possibilities that it can come up have been rolled on 3 die, which is an automatic win.The code is as follows:

sub Roll456{ #in main i have a list that excepts 3 different random #'s 1-6

my($Hand) = $Dice[0] . $Dice[1] . $Dice[2]; #put into a string for pattern matching

if($Hand =~ /4(56|65)/){


print "Player has automatically won!\n"


elsif($Hand =~ /5(46|64)/){


print "Player has automatically won!\n";


elsif($Hand =~ /6(45|54)/){


print "Player has automatically won!\n";




(This post was edited by LoGiCaL_ on Aug 31, 2009, 7:51 PM)


Aug 31, 2009, 9:32 PM

Post #2 of 2 (340 views)
Re: [LoGiCaL_] Sub Routine Question [In reply to] Can't Post

You could do it all in one condition cleverly like this:


sub Roll456{
if ( 456 == join('',sort {$a <=> $b} @_)) {
print "Player has automatically won!\n"



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives