in reply to If Simplification

my $req_uri_re = join '|', map quotemeta, qw( /bulletin/ .css .ico formmail /prosp/ /calendar/ /edit/ /tmp/calendar2002-3/pgradh/regs/029.html/ ); if ($ENV{'HTTP_REFERER'} and $ENV{'REMOTE_ADDR'} ne "129.215.67.96" and $ENV{REQUEST_URI} !~ $req_uri_re) { }
And your pseudocode, in real code, might look like this
## false if $ENV{'REQUEST_URI'} contains "FalseIfJustThis" if($ENV{REQUEST_URI} !~ $regex) { } ## true if $ENV{'REQUEST_URI'} contains "FalseIfJustThis" ## AND contains "ButIfAlsoThisThenTrue") if($ENV{REQUEST_URI} =~ $regex and $ENV{REQUEST_URI} =~ $regex2) { }
See. perlop and perlre for more info.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: If Simplification
by fourmi (Scribe) on Aug 07, 2003 at 11:10 UTC
    If i roll the two pseudocode if statements together then the following IS valid (isn't it?)
    if (($ENV{REQUEST_URI} !~ $regex) || ($ENV{REQUEST_URI} =~ $regex and + $ENV{REQUEST_URI} =~ $regex2)) {}
    I thought it would end up being fairly straightforward, I think my problem was trying to do the whole lot at once rather than bits at a time, and then combine, cheers for that!
Re^2: If Simplification
by Aristotle (Chancellor) on Aug 07, 2003 at 15:45 UTC
    Or if you want to do the same thing in both cases, you can do with only a single evaluation:
    if( $ENV{REQUEST_URI} =~ $regex ? $ENV{REQUEST_URI} =~ $regex2 : 1 ) { # ... }
    Which reads a lot less awkwardly using $_.
    local $_ = $ENV{REQUEST_URI}; if(/$regex/ ? /$regex2/ : 1) { # ... }
    In other words, if matching $regex succeed, then it depends on whether it matches $regex2, if it failed, then it's always true.

    Makeshifts last the longest.