>>>>> "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/


Reply via email to