When to use ( and when to use ((?

I'm just not getting it.
When do you use ( in a statement, when do you need to use ((, and is
the space after either or both mandatory?
For example, I coded this statement:
if (( $_ eq $bad_guys_ip )) { more_stuff_here };
Why the two (( in an if?  And why does it seem to not work when I miss
the space after the ((?
Thanx!
Mark me as...
/Corn-fused|Dense/

-1
mweber
3/14/2003 11:18:28 PM
📁 perl.beginners
📃 29388 articles.
⭐ 4 followers.

💬 3 Replies
👁️‍🗨️ 3124 Views


> I'm just not getting it.
>=20
> When do you use ( in a statement, when do you need to use ((, and is
> the space after either or both mandatory?
>=20
> For example, I coded this statement:
>=20
> if (( $_ eq $bad_guys_ip )) { more_stuff_here };
(( )) is ksh integer test syntax, and has nothing to do with perl. Just =
use ( ).
-2
Luke
3/14/2003 11:24:04 PM
Michael Weber wrote:
> I'm just not getting it.
>
> When do you use ( in a statement, when do you need to use ((, and is
> the space after either or both mandatory?
>
> For example, I coded this statement:
>
> if (( $_ eq $bad_guys_ip )) { more_stuff_here };
>
> Why the two (( in an if?  And why does it seem to not work when I miss
> the space after the ((?
If this is pure Perl then it doesn't make any difference.
    if         (
                                ($_
    eq $bad_guys_ip)                  )
{more_stuff_here         };

is fine (although the second pair of parentheses won't make any
difference either) as long as you also have a
    sub more_stuff_here;
somewhere!
Can you give us a
bit more context, and say what error you're getting?
Cheers,
Rob

0
rob
3/15/2003 12:01:29 AM
Michael Weber wrote:
> 
> I'm just not getting it.
> 
> When do you use ( in a statement, when do you need to use ((, and is
> the space after either or both mandatory?
> 
> For example, I coded this statement:
> 
> if (( $_ eq $bad_guys_ip )) { more_stuff_here };
> 
> Why the two (( in an if?  And why does it seem to not work when I miss
> the space after the ((?
You don't need two parenthesis pairs in that context, if fact, you don't
need any whitespace at all.
if(${_}eq$bad_guys_ip){more_stuff_here}

John
-- 
use Perl;
program
fulfillment
0
krahnj
3/15/2003 1:04:32 AM
Reply: