Your problem is that you are commenting out the latter part of your for loop and thus the if statement is interpreted as in the second part of the for loop, and a syntax error. The offending code segment is:

#do a for loop to make it go through the test for ($i=0; $i<=#@Comment; $i++) { #Do an if loop to go through and save the right thing if ($value == $Comm[$i]) { $Como = $Comment[$i]; } }

When perl parses this, it interpretes it as:

for($i=0; $i <= if ($value==$Comm[$i]) { ....

Because the #@Comment ... starts a comment. You probably meant to use $#Comment instead. Alternately, it might be better to re-write that for loop to use the foreach-style:

my $Como; foreach my $i (0..$#Comment) { $Como = $Comment[$i], last if $Comm[$i] == $value; } # ... and you should add error-checking: unless (defined $Como) { # do something here if we didn't find anything }

update: but, you are trying to compare $value to string, so you should replace that == (which compares things as numbers) with an eq (which compares them as strings):

# ... $Como = $Comment[$i], last if $Comm[$i] eq $value;

(Note that you could write that statement using the if (...) { ... } form, too, of course. You may find that clearer.)

In the future it would be a good idea to use strict and warnings. And taint checks.


In reply to Re: Printing the comment by wog
in thread Printing the comment by Anonymous Monk

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.