Home > Archive > PERL Beginners > October 2004 > assign operator as variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
assign operator as variable
|
|
| Khairul Azmi 2004-10-25, 8:55 am |
| 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
| |
| Gabor Urban 2004-10-25, 8:55 am |
| 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
| |
| Khairul Azmi 2004-10-25, 8:55 am |
| 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>
>
>
| |
| Marcos Rebelo 2004-10-25, 8:55 am |
| 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>
| |
| Khairul Azmi 2004-10-25, 8:55 am |
| 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>
>
>
|
|
|
|
|