if (@recordset[$i] && (@recordset[$i]->[1] == "exit")){ ... }

Another change you might consider is to add  use warnings; and  use strict; (see warnings and strict) at the top of your script. warnings would have warned about a string comparison using the  == numeric comparator. The expression  @recordset[$i]->[1] == "exit" will only be true if  @recordset[$i]->[1] (another warning) or better yet  $recordset[$i]->[1] or even  $recordset[$i][1] (no warning, but  -> is redundant) is 0. (Update: In numeric context, a string like 'exit' or 'foo' or '' evaluates to 0.)

Update 1: Some example code (note: no warnings, but strictures enabled):

c:\@Work\Perl>perl -Mstrict -le "print 'A: equal' if 0 == 'exit'; print 'B: equal' if 'exit' == 'exit'; print 'C: equal' if 'foo' == 'exit'; print 'D: equal' if 1 == 'exit'; " A: equal B: equal C: equal

Update 2: In many cases, a warning is referred to as an 'error'; there are many examples of this on PerlMonks. But a warning is not an error; it is, well, a warning: something that looks odd to the Perl interpreter and that the interpreter is telling you about because you asked it to. As long as you don't mind having whatever  STDERR points to fill up with umpteen warning messages, Perl is perfectly happy to soldier on. There are, however, some cases in which a warning alludes to a serious semantic error, as when 0 or 'foo' is numerically compared to 'exit' and found to be equal! Bottom line, especially if you're a Perl novice: always ask for warnings; always pay close attention to them. (And IMHO, always eliminate their source.)

Update 3: And I should have said this long since: the proper equality operators for string comparison are  eq and  ne (see Equality Operators in perlop).


In reply to Re: Trouble with array of arrays by AnomalousMonk
in thread Trouble with array of arrays by trew

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.