Since you're going to have to rewrite the code to step through each entry individually, telling you this isn't cheating.

A common mistake for people learning Perl (even if they're experienced programmers) is to learn what those funny characters mean. You can't say:

if (@input eq 'q') {

- because the @ funny character indicates an array(see #1) .

So @input indicates the whole array - making it nonsensical to ask if the array is equal to anything (see #2). If you want to ask if a particular element of an array is equal to anything, you have to refer to that element explicitly, using the $ funny character. So, to test the first element of an array, we do somthing like this:

@foo = ('Bob', 'Tim', 'Bongo - The Jungle Avenger'); if ($foo[0] eq 'Bob') { #The $ indicates a single element #and [0] indicates which one print "Everything has gone as planned"; }


Cheers,
Erik

#1 - Well, not exactly true. It indicates a list out of a data structure, so it could be an array or and array slice or a hash slice.

#2 - Also not entirely true. The @input is in scalar context, so it does make sense to ask if it's equal to something . . .just not the sense we think it does.


In reply to Re: A quit key when no chomp by erikharrison
in thread A quit key when no chomp by ellem

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.