Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Proper use of And

by grashoper (Monk)
on Jan 09, 2008 at 20:37 UTC ( [id://661494]=perlquestion: print w/replies, xml ) Need Help??

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

I cannot seem to write and properly.. for example..

if ($Session->{'usrType'} eq 'Pro') and ($Session->{'usrSystem'}=~/SEF +/VAL/SUM/SAR/MRT/ALB/MRE/VER/RML/AUS/ORG/MSX/BAR/LAS/)){$Response->wr +ite('found a match!'}

this won't work whether I use and or && I am not sure why it seems everything I do is a syntax error.. are my parens out of whack? something is still wrong..

here is my revised version..

if (($Session->{'usrType'} eq 'Pro') and ($Session->{'usrSystem'}=~/SE +F|VAL|SUM|SAR|MRT|ALB|MRE|VER|RML|AUS|ORG|MSX|BAR|LAS/); { $Response->Write("found a match"); }

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: Proper use of And
by philcrow (Priest) on Jan 09, 2008 at 20:43 UTC
    You have two main problems. One is your if is missing an opening paren:
    if ( ( $Session... ) and ( ... ) ) { # ^ this one is missing
    Also, your regex is apparently using / for alternation. You probably meant something like:
    ($Session->{ usrSystem } =~ /SEF|VAL|.../ )
    Phil
    The Gantry Web Framework Book is now available.
Re: Proper use of And
by apl (Monsignor) on Jan 09, 2008 at 20:47 UTC
    Bracketing your example with <code> and </code>
    if ($Session->{'usrType'} eq 'Pro') and ($Session->{'usrSystem' =~/SEF/VAL/SUM/SAR/MRT/ALB/MRE/VER/RML/AUS +/ORG/MSX/BAR/LAS/) {do something}
    I can see several typos. It should look like:
    if ( ($Session->{'usrType'} eq 'Pro') and ($Session->{'usrSystem'} =~/SEF/VAL/SUM/SAR/MRT/ALB/MRE/VER/RML/AU +S/ORG/MSX/BAR/LAS/)) {do something}
    You should always use use strict; use warnings; If there's still a problem, have you considered displaying the values of $Session->{usrType} and $Session->{usrSystem}?
      Again, as philcrow already pointed out,

          /SEF/VAL/SUM/SAR/MRT/ALB/MRE/VER/RML/AUS/ORG/MSX/BAR/LAS/

      should be

          /SEF|VAL|SUM|SAR|MRT|ALB|MRE|VER|RML|AUS|ORG|MSX|BAR|LAS/

Re: Proper use of And
by apl (Monsignor) on Jan 09, 2008 at 23:25 UTC
    You don't want a semicolon at the end of the conditional; you want another closing parentheses.
Re: Proper use of And
by apl (Monsignor) on Jan 09, 2008 at 21:38 UTC
    For the love of Charles Babbage, please bracket your examples with <code> and </code> !

      Where is your Charles Babbage now?

      @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-29 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found