Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

multiple 'or''s

Posted on 2004-10-02
11
Medium Priority
?
151 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 800 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
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.

 
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 85

Accepted Solution

by:
ozo earned 1200 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 85

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 85

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 85

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

971 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