iceraider has asked for the wisdom of the Perl Monks concerning the following question:

my @required = qw(name site siteid email email2 pass repass); my $req_err; for (@required) { next if $q->param($_); $req_err++; last; } if ($req_err) { &error("You forgot some required fields"); }
How can I do something like but check for | characters.

Title edit by tye

Replies are listed 'Best First'.
Re: disallowing vertical bar characters
by r0b (Pilgrim) on Jun 11, 2002 at 19:37 UTC
    The following tests if the required key exists or if a required field's value contains a | character. In @failed is a list of all the fields that didn't pass the test.
    my @failed = grep {!($q->param($_)) || $q->param($_)=~/\|/} @required;

    ~~rob
    ____________________________________________________________
    eval pack "h*", "072796e647022245d445f475454494c5e622b3";

Re: disabling 's
by talexb (Chancellor) on Jun 11, 2002 at 18:14 UTC
      How can I do something like but check for | characters.

    And what do you want to do when you find | characters? Delete them? Replace them with spaces? Increment the number of errors? Do you actually mean ' characters instead?

    You have to help us out here .. we can't make head or tail of your request. Please preview your posts and check them carefully. This saves everyone time.

    <rant>
    And don't re-post a question .. that doesn't sit well with the community, and it's another time-waster. Post a good quality, well phrased question once, and then wait for the answers. Please.
    </rant>

    --t. alex

    "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Re: disallowing vertical bar characters
by cLive ;-) (Prior) on Jun 12, 2002 at 09:17 UTC
    If I understand you:
    for (@required) { if ($q->param($_) =~ /\|/) { $req_err++; last; } next if $q->param($_); $req_err++; last; }
    cLive ;-)

    --
    seek(JOB,$$LA,0);

Re: disallowing vertical bar characters
by iceraider (Initiate) on Jun 11, 2002 at 18:39 UTC
    I check to see in each field if the put a verticl bar in, if they did than, show and error saying they have.