Perlのsmart match演算子

  • 103 views
Uploaded on

Review of Smart match for LT at Hatena on 2013/08/23.

Review of Smart match for LT at Hatena on 2013/08/23.

More in: Sports , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
103
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. ~~ in perl id:astj
  • 2. Ø| m−oó$aw =ê@b”Ì• m−v−ߤo x
  • 3. ž $a = 3; @b = (1,2,3,4); foreach $elem (@a) { return 'Hit!' if $elem == $a; } «ł› ¾Í–ƒq grep { $a == $_ } @b;
  • 4. perl 5.10 ı “
  • 5. ~~/æÄ
  • 6. $a ~~ @b @b”Ì•$awm− xÕþßç•þáÞ|—¡ use 5.010; $a = 3; @b = (1,2,3,4); print "Hit!n" if $a ~~ @b;
  • 7. Õþßç ¡„
  • 8. $a ~~ %c îáÓ™”ô»Éß³¢—¡ use 5.010; $a = "Steve"; %c = ( "Steve" => "Jobs", "Bill" => "Gates" ); print "Hit!n" if $a ~~ %c;
  • 9. oo ¡„
  • 10. m› ô¹ Õ Øq÷ö ¡ (Ø|v|¤œ5.14m¤ßvœvØ) $a = 3; $b = (1,2,3,4); print "Hit!n" if $a ~~ $b; «¶Æ•5.14vœpush vpop vkeys vØ ô¹ Õ −œ|o ¡„
  • 11. $a ~~ $d $a == $dºœ$a eq $dºœ ø|¶•́°©—¡
  • 12. ̂̂̂¶µvó^ ¡„
  • 13. @a ~~ @b $a = [1,2,3]; $b = [1,2,3]; print "Smart match!n" if $a ~~ $b; # match! ž O $p = [ 1, 2, 3 ]; $q = [ 1, 2, 3, 4 ]; print "Smart match!n" if $p ~~ $q; # matchしない! $r = [ 1, 2, 3 ]; $s = [ 1, 2, [ 3, 4, 5 ] ]; print "Smart match!n" if $r ~~ $s; # matchするんだなぁ µµ̇
  • 14. perl 5.16”perldoc¢− Right operand is an ARRAY: Left Right Description and pseudocode =============================================================== ARRAY1 ARRAY2 recurse on paired elements of ARRAY1 and ARRAY2[2] like: (ARRAY1[0] ~~ ARRAY2[0]) && (ARRAY1[1] ~~ ARRAY2[1]) && ... HASH ARRAY any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY Regexp ARRAY any ARRAY elements pattern match Regexp like: grep { /Regexp/ } ARRAY undef ARRAY undef in ARRAY like: grep { !defined } ARRAY Any ARRAY smartmatch each ARRAY element[3] like: grep { Any ~~ $_ } ARRAY
  • 15. =êœÀ”~~“ oóÀ•~~|–−” $a = [ 1, 2, 3 ]; $b = [ 1, 2, [ 3, 4, 5 ] ]; •u¦−($a ~~ $b) »fi—ß ( 1 ~~ 1 ) && ( 2 ~~ 2 ) && ( 3 ~ [3,4,5] ) # TRUE && TRUE && TRUE
  • 16. ž O∼Œ¶z¶›–x¤
  • 17. îáÓ™» Left Right Description and pseudocode =============================================================== HASH1 HASH2 all same keys in both HASHes like: keys HASH1 == grep { exists HASH2->{$_} } keys HASH1 ARRAY HASH any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY Regexp HASH any HASH keys pattern match Regexp like: grep { /Regexp/ } keys HASH undef HASH always false (undef can''t be a key) like: 0 == 1 Any HASH HASH key existence like: exists HASH->{Any}
  • 18. Keysm›–© Value»∙q Øooœ|o $a = { "Steve" => "Jobs", "Bill" => "Gates" }; $b = { "Steve" => "Ballmer", "Bill" => "Gates" }; print "Smart match!n" if $a ~~ $b; # matchする!!
  • 19. ∙µ∙µ |z¶›–x¤
  • 20. H•Øo¬o¬ |z–ºº̃|z–
  • 21. —ÞO•Øº }œ|o” ( id:moznion œ) oÚ¹ô½ßèïáË: ̃©̌” Èo |¤
  • 22. The smartmatch family of features are now experimental
  • 23. 5.18 g©¤" ‹O"¶)Ô•yß7—© ³°¶ozwooø„•¶›–|—o—|¤
  • 24. ï
  • 25. ǵ C›̃”$a ~~ @b»ƒ©¶ß•oo ∼“ Êq ” ofiv¡›xß|–a›–z− ∼– :ŸØgrep|–Ûe|—|łq
  • 26. u|—o