Solved

multiple 'or''s

Posted on 2004-10-02
11
144 Views
Last Modified: 2010-03-05
Hi,
 
can anyone tell whats wrong here?
this is the output from the debugger  for

 if ($dd && $ee eq ('a||'b'||'c'||'d')) { dosomething};

when ee equaled c the xpression ee eq ('a||'b'||'c'||'d') still evaluated to false?
when ee was a and b it evaluated correctly....
whats wrong here?


heres the o/p from debugger:

DB<5> x  ($dd eq 'a' && $ee eq ('a'||'b'||'c'||'d'))
0  ''
  DB<6> x  dd
0  'a'
  DB<7>
  DB<8> $ee

  DB<9> x $ee
0  'c'
 
  DB<14> x  ($ee eq ('a'||'b'||'c'||'d'))
0  ''
  DB<15>
0
Comment
Question by:Vlearns
  • 5
  • 4
  • 2
11 Comments
 

Author Comment

by:Vlearns
ID: 12210003
it didnt worlk for ee equals d or b
it works only for a

how to define this such that it is true when either of a b c or d is true



0
 

Author Comment

by:Vlearns
ID: 12210035
how to define a expression such that value is true if ee equals one of a, b,c, or d
0
 
LVL 18

Assisted Solution

by:kandura
kandura earned 200 total points
ID: 12210044
Do you know what ('a'||'b'||'c'||'d') evaluates to?
hint: try "print ('a'||'b'||'c'||'d')"...

What you want is a regular expression:

    $ee =~ /^a|b|c|d$/
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 18

Expert Comment

by:kandura
ID: 12210051
or
    $ee =~ /^[a-d]$/
0
 

Author Comment

by:Vlearns
ID: 12210075
yes it evaluates to first a
i wrote to ((ee eq a)||(ee eq b) || () ||())

to correct that but looking for a better sol
0
 

Author Comment

by:Vlearns
ID: 12210089

or operators in perl dont worlk loike in C
not very familiar with perl

in ur soln  $ee =~ /^a|b|c|d$/


^ means matches at the start and $ means matching at end?
in general if i need $ee =~/^ant/man/sky/earth$/

will this match if ee is one of these?



the dollar towards the end means
0
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 12210112
$ee eq 'a' ||$ee eq 'b'||$ee eq 'c'||$ee eq 'd'

$ee =~ /^(a|b|c|d)$/;

grep{$_ eq $ee}qw(a b c d)

${{a=>1,b=>1,c=>1,d=>1}}{$ee}
0
 
LVL 84

Expert Comment

by:ozo
ID: 12210134
$ee="trotskyism";
$ee =~/^ant|man|sky|earth$/
will match

You must use
$ee =~/^(ant|man|sky|earth)$/
to match "sky" exactly.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12210202
Actually
$ee =~/^(ant|man|sky|earth)$/
will also match "ant\n" or "man\n" or "sky\n" or "earth\n"
better to use
$ee =~/\A(ant|man|sky|earth)\z/
see
perldoc perlre
0
 
LVL 84

Expert Comment

by:ozo
ID: 12213215
In Perl6 you will be able to say
  if( $ee eq any('a'..'d') ){
You can also use that construct in Perl5 if you
   use Quantum::Superpositions;
0
 

Author Comment

by:Vlearns
ID: 12273855
Thanks folks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP equivalent of opening a com object 5 89
Exchange 2010 Transport Rule Regex 28 118
Using Perl DBI to query oracle 3 46
Perl Frameworks 1 97
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question