John W. Krahn wrote: > Steve Bertrand wrote: >>> 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/); > > In a word, yes. > > $ perl -MO=Deparse,-p -e'ref $href =~ /HASH/' > ref(($href =~ /HASH/)); > -e syntax OK > $ perl -MO=Deparse,-p -e'ref( $href ) =~ /HASH/' > (ref($href) =~ /HASH/); > -e syntax OK > > Perhaps you meant to use the higher precedence operator eq: > > $ perl -MO=Deparse,-p -e'ref $href eq "HASH"' > (ref($href) eq 'HASH'); > -e syntax OK
Thanks John, I thought afterword that it had to do with precedence. I'll stick to using brackets when I know I need the left side evaluated before moving forward. Still on topic, I'm trying to write an is() test against an object method, where the method die()s the entire program with an error message if a very specific parameter is not passed in. I don't want to change the object method's behaviour just for a test, so can anyone point me in the right direction as to how I can override the object method's needed die() statement on the test side, so the method I'm testing doesn't die() the test? A bit of context...the test statement, and the death of the test: is ($user->add_plan(\%plan_info), 0, "Don't want to die()!"); ... Bad API call to ISP::Sanity::plan_info from ISP::User::add_plan: You did not supply an ISP::Error object Please read "perldoc ISP::Sanity" for proper API use Steve
smime.p7s
Description: S/MIME Cryptographic Signature