----- Forwarded Message ----
From: Soham Das <[email protected]>
To: Uri Guttman <[email protected]>
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 <[email protected]>
To: John W. Krahn <[email protected]>
Cc: Perl Beginners <[email protected]>
Sent: Thursday, 16 July, 2009 5:44:26 AM
Subject: Re: Modifiers on the right side of the statement

>>>>> "JWK" == John W Krahn <[email protected]> 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  ------  [email protected]  --------  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: [email protected]
For additional commands, e-mail: [email protected]
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&#39;s breaking stories, chosen by people like you. Check out 
Yahoo! Buzz. http://in.buzz.yahoo.com/

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to