Please forgive the title if it's not quite descriptive enough but here's my dilema.
I'm writing a solitare game in Perl/Tk and I have 5 arrays with 5 elements each. I thought about using a 2 dimensional array, but I am unsure how you would unshift a value off that type of data structure, so for the present I'm sticking to the 5 arrays.
I'm trying to use eval to build the code to compare two array values, but I am getting an error saying that the index, that I am trying to concatenate with my array base name, needs to be defined.
Here's the code I've been playing with to test this:
#!/usr/bin/perl -w use strict; my ($i, $j); my @a1=(1,2,3,4,5); my @a2=(2,1,3,5,4); my @a3=(3,4,5,1,2); my @a4=(4,2,3,5,1); my @a5=(5,4,3,2,1); for $i(1..4){ for $j($i+1..5){ if (eval{$a.$i}[0] == eval{$a.$j}[0]){ print "Matched one!\n"; last}; }; };
Can someone possibly shed some light on how I can accomplish what I'm trying to do? I'd rather do it this way than a series of if match then last type of thing.
Thanks in advance!
Some people fall from grace. I prefer a running start...
In reply to Using eval to build array structure by Popcorn Dave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |