----- Forwarded Message ----
From: Soham Das <soham...@yahoo.co.in>
To: Uri Guttman <u...@stemsystems.com>
Sent: Thursday, 16 July, 2009 11:23:29 AM
Subject: Re: Modifiers on the right side of the statement
I believe its because =~ has the highest priorty...
----- Original Message ----
From: Uri Guttman <u...@stemsystems.com>
To: John W. Krahn <jwkr...@shaw.ca>
Cc: Perl Beginners <beginners@perl.org>
Sent: Thursday, 16 July, 2009 5:44:26 AM
Subject: Re: Modifiers on the right side of the statement
>>>>> "JWK" == John W Krahn <jwkr...@shaw.ca> writes:
>>> Can someone point out the importance of the brackets in which '2'
>>> prints, but '1' does not? I've always thought that the brackets could be
>>> omitted:
>>>
>>> print "1" if ref $href =~ /HASH/;
>>> print "2" if ref($href) =~ /HASH/;
>>
>> ... is it because ref() is trying to work like this?:
>>
>> ref ($href =~ /HASH/);
JWK> In a word, yes.
JWK> Perhaps you meant to use the higher precedence operator eq:
i think you mean lower precedence. eq lets ref eat its single arg and
then compares it to 'HASH'. the comparison ops are generally low binding
compared to the math and similar ops (and =~ is just below the math ops
in the precedence table).
and to the OP, when checking for ref types use eq as a regex is overkill
and slower. you know the ref type will be a fixed known string.
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
Yahoo! recommends that you upgrade to the new and safer Internet Explorer
8. http://downloads.yahoo.com/in/internetexplorer/
See the Web's breaking stories, chosen by people like you. Check out
Yahoo! Buzz. http://in.buzz.yahoo.com/
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/