Link to home
Start Free TrialLog in
Avatar of Vlearns
Vlearns

asked on

multiple 'or''s

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>
Avatar of Vlearns
Vlearns

ASKER

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



Avatar of Vlearns

ASKER

how to define a expression such that value is true if ee equals one of a, b,c, or d
SOLUTION
Avatar of kandura
kandura

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or
    $ee =~ /^[a-d]$/
Avatar of Vlearns

ASKER

yes it evaluates to first a
i wrote to ((ee eq a)||(ee eq b) || () ||())

to correct that but looking for a better sol
Avatar of Vlearns

ASKER


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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$ee="trotskyism";
$ee =~/^ant|man|sky|earth$/
will match

You must use
$ee =~/^(ant|man|sky|earth)$/
to match "sky" exactly.
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
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;
Avatar of Vlearns

ASKER

Thanks folks