Re: Question with Perl script

by "Ryan Fischer" <ryan(at)gigabee.com>

 Date:  Fri, 21 Dec 2001 01:55:55 -0500
 To:  <design(at)chronotope.com>,
<hwg-languages(at)hwg.org>
 References:  filonov
  todo: View Thread, Original
You wrote:
> I can't seem to figure this out and was hoping to get some outside
> opinions on this.  I am checking a string and would like to have one
of
> three results.
>
> If the string is empty I want one result.  If the string falls into
one
> of these (1011,1012, or 1013) I want another result.  Or if the string
> is not empty but falls outside of the &af; filter, for example 1014,
> then I want a third result.
>
> This script works well for 2 of the 3 but I can't seem to figure out
why
> I can't catch all three potential results.
>
> I would appreciate any pointers on what I'm doing wrong.
>
> TIA.
>
> Chris
>
>
> $null = "";
> &af_check;
> sub af_check {
>      if ($querystring == $null) {
>      $cfg = "z";
>      } elsif ($cfg == $null) {
>      &af;
>      } elsif ($cfg == $null) {
>      $cfg = "x";
>      }
> }
>
> sub af {
>      for ($querystring) { $cfg = /1011/ && "a"
>      || /1012/ && "b"
>      || /1013/ && "c"
>      }
> }

Well, you're using assignment instead of the binding "=~" operator.  If
you want to check a variable against a regular expression, you need to
do something like:

$cfg =~ /1011/

And, well, it seems like some of your other logic is a little off, too.
I could write the code for you, but where's the fun in that?  ;)

Seriously, just take it one step at a time.  You have three different
conditions (at least), so just construct your if block as needed.
Here's a start:

if($cfg eq ''){
    # String is empty
}elsif($cfg =~ /^101[1-3]$/){
    # is one of those three numeric cases
}# and so on...

HTH!  :)

--
 -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA