Solved

multiple 'or''s

Posted on 2004-10-02
11
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

627 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