Smart matching
--------------060209010700080108050904
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
I'm trying to check whether the given key exists in the hash.
The simple example:
use feature ':5.10';
my %a = (a => 1, b => 2);
say %a ~~ 'a' ? 'YES' : 'NO'; # says NO -- why?
say %a ~~ 'c' ? 'YES' : 'NO'; # says NO
say 'a' ~~ %a ? 'YES' : 'NO'; # says YES
say 'c' ~~ %a ? 'YES' : 'NO'; # says NO
There is a description of smart mathing operator:
http://search.cpan.org/~rgarcia/perl-5.10.0-RC1/pod/perlsyn. pod#Smart_matching_in_detail
"...The behaviour of a smart match depends on what type of thing its
arguments are. It is always commutative, i.e. |$a ~~ $b| behaves the
same as |$b ~~ $a|..."
Why is the result of %a ~~ 'a' differs from the result of 'a' ~~ %a ?
--------------060209010700080108050904--
Re: Smart matching
>>>>> "VDB" == Vladimir D Belousov <maillist [at] klarnet.ru> writes:
VDB> I'm trying to check whether the given key exists in the hash.
smart matching is powerful and cool but why don't you just call exists
on the hash key? there is no win to using smart matching for that. it is
included for consistancy but it isn't needed for hash keys.
uri
--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Smart matching
19.01.2011 0:09, Uri Guttman пишет:
> but why don't you just call exists on the hash key? there is no win to
> using smart matching for that. it is included for consistancy but it
> isn't needed for hash keys.
>
I just want to understand how does it work :)
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Smart matching
--001636c5a8600e0df9049a25c908
Content-Type: text/plain; charset=ISO-8859-1
The smart match is no longer commutative - That was removed after 5.10.1, I
think.
http://www.learning-perl.com/?p=32
http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detai l
Brian.
--001636c5a8600e0df9049a25c908--
Re: Smart matching
19.01.2011 0:43, Brian Fraser пишет:
> The smart match is no longer commutative - That was removed after 5.10.1, I
> think.
>
> http://www.learning-perl.com/?p=32
> http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detai l
>
> Brian.
>
Thank you!
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/