I'm not exactly sure if you know the difference between what you want and what you wrote (and how Perl interprets that).

What you want seems to be the statement "No field may contain a vertical bar".

What you wrote is a translation from english to Perl like "If the name or the site or ... or the intrests contain a vertical bar, return an error ".

What Perl makes of your sentence is "If the name is not the empty string and not 0 or the site is not the empty string and not 0 or ... or the interests contain a vertical bar, return an error".

This is obviously not what you wanted. There are two ways to approach what you want to achieve. Either reformulate your intention - if no single string may contain a vertical bar, then also the concatenation of these strings may not contain a vertical bar. Or create a predicate function, has_vertical_bar, which tells you if a single string contains a vertical bar :

sub has_vertical_bar { my ($string) = @_; return $string =~ /\|/; }; # ... later, in your code ... my @parameters = qw(name site siteid email pass aim yahoo icq msn loca +tion intrests ); my $errormsg = ""; foreach my $parameter (@parameters) { if has_vertical_bar($q->param($parameter)) { $errormsg ||= "There was some problem with your input. Please make + sure no fields have vertical bars."; $errormsg .= "I found a vertical bar in the field $parameter. "; }; }; error($errormsg) if ($errormsg);

Update: You might also want to take a look at disallowing vertical bar characters, which (strangely enough) seems to revolve about a similar problem.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

In reply to Re: using logical in if statement by Corion
in thread using logical in if statement 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.