Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Printing the comment

by wog (Curate)
on Oct 06, 2001 at 03:58 UTC ( [id://117145]=note: print w/replies, xml ) Need Help??


in reply to Printing the comment

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found