Solved

multiple 'or''s

Posted on 2004-10-02
11
139 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to tell if a file is being written with Perl running on a Windows 2003 Server 12 36
collecting information 2 140
instmodsh - listing perl modules 2 74
Awk Question 2 124
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 …
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now