at first glance the two if-statement blocks differ only in the constants "red" and "blue".
You can factor them out in a common sub:
sub good_sub_name_here {
my ($color, $other_color) = @_;
if ($old_color eq $color) {
if ($_ == 1) {
alert(1);
} elsif ($button[$_-1]->cget(-background) eq $color) {
alert(2);
} elsif ($_ >= 2 && $button[$_-1]->cget(-background) eq $other_col
+or && $button[$_-2]->c
+get(-background) ne "white") {
alert(3);
} elsif ($button[$_-1]->cget(-background) eq "white") {
make_color ($color, $_-1);
make_blank ($_);
check_win();
} else {
make_color ($color, $_-2);
make_blank ($_);
check_win();
}
}
}
# and call it:
good_sub_name_here(qw(blue red))
good_sub_name_here(qw(red blue))
If you declare the sub in the place where the if blocks are now, you shouldn't have any scoping issues
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.