Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

assign operator as variable
I am not sure what category should this question fall under but this
is what I plan to do.

$cond1 = 1;
$cont2 = 0;
$oper1="&&"; # for AND
$oper2="||"; # for OR

if ($cond1 $oper1 $cond2) {
print "one \n";
} else {
print "two \n";
}

The statement above would generates errors. Can somebody tell me how
to do it in proper way. Thanks

Azmi

Report this thread to moderator Post Follow-up to this message
Old Post
Khairul Azmi
10-25-04 01:55 PM


Re: assign operator as variable
On Mon, 2004-10-25 at 11:39, Khairul Azmi wrote:
> I am not sure what category should this question fall under but this
> is what I plan to do.
>
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
>
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
>
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
>
> Azmi

Hi, did you try to use the function eval?

Check perldoc

I think this should help you.

Gabaux


Report this thread to moderator Post Follow-up to this message
Old Post
Gabor Urban
10-25-04 01:55 PM


Re: assign operator as variable
Actually I am looking for an alternative to replace the conventional
symbol "&&" with other variable eg $AND_operator so that the following
statement is valid

if ($cond1 $AND_operator $cond2)

Thanks


On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
<marcos.rebelo@edisoft.pt> wrote:
> Maybe this can help
>
> $a = "1 or 0"; print eval($a);
>
>
>
> -----Original Message-----
> From: Khairul Azmi [mailto:khairul.azmi@gmail.com]
> Sent: segunda-feira, 25 de Outubro de 2004 10:40
> To: beginners@perl.org
> Subject: assign operator as variable
>
> I am not sure what category should this question fall under but this
> is what I plan to do.
>
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
>
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
>
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
>
> Azmi
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Khairul Azmi
10-25-04 01:55 PM


RE: assign operator as variable
if (eval("$cond1 $AND_operator $cond2"))

is this correct?

-----Original Message-----
From: Khairul Azmi [mailto:khairul.azmi@gmail.com]
Sent: segunda-feira, 25 de Outubro de 2004 11:00
To: beginners@perl.org
Subject: Re: assign operator as variable

Actually I am looking for an alternative to replace the conventional
symbol "&&" with other variable eg $AND_operator so that the following
statement is valid

if ($cond1 $AND_operator $cond2)

Thanks


On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
<marcos.rebelo@edisoft.pt> wrote:
> Maybe this can help
>
> $a = "1 or 0"; print eval($a);
>
>
>
> -----Original Message-----
> From: Khairul Azmi [mailto:khairul.azmi@gmail.com]
> Sent: segunda-feira, 25 de Outubro de 2004 10:40
> To: beginners@perl.org
> Subject: assign operator as variable
>
> I am not sure what category should this question fall under but this
> is what I plan to do.
>
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
>
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
>
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
>
> Azmi
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Report this thread to moderator Post Follow-up to this message
Old Post
Marcos Rebelo
10-25-04 01:55 PM


Re: assign operator as variable
Yes. Silly me. I put the eval operator right before variable
$AND_operator. Thanks a lot guys.


On Mon, 25 Oct 2004 11:03:24 +0100, Marcos Rebelo
<marcos.rebelo@edisoft.pt> wrote:
> if (eval("$cond1 $AND_operator $cond2"))
>
> is this correct?
>
> -----Original Message-----
> From: Khairul Azmi [mailto:khairul.azmi@gmail.com]
> Sent: segunda-feira, 25 de Outubro de 2004 11:00
> To: beginners@perl.org
> Subject: Re: assign operator as variable
>
> Actually I am looking for an alternative to replace the conventional
> symbol "&&" with other variable eg $AND_operator so that the following
> statement is valid
>
> if ($cond1 $AND_operator $cond2)
>
> Thanks
>
> On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
> <marcos.rebelo@edisoft.pt> wrote: 
>
> --
>
>
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Khairul Azmi
10-25-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:46 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.