Fellow monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.