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>
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>
ASKER
how to define a expression such that value is true if ee equals one of a, b,c, or d
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
$ee =~ /^[a-d]$/
$ee =~ /^[a-d]$/
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
i wrote to ((ee eq a)||(ee eq b) || () ||())
to correct that but looking for a better sol
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$ee="trotskyism";
$ee =~/^ant|man|sky|earth$/
will match
You must use
$ee =~/^(ant|man|sky|earth)$/
to match "sky" exactly.
$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
$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;
if( $ee eq any('a'..'d') ){
You can also use that construct in Perl5 if you
use Quantum::Superpositions;
ASKER
Thanks folks
ASKER
it works only for a
how to define this such that it is true when either of a b c or d is true