• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Perlのsmart match演算子
 

Perlのsmart match演算子

on

  • 129 views

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

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

Statistics

Views

Total Views
129
Views on SlideShare
129
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Perlのsmart match演算子 Perlのsmart match演算子 Presentation Transcript

    • ~~ in perl id:astj
    • Ø| m−oó$aw =ê@b”Ì• m−v−ߤo x
    • ž $a = 3; @b = (1,2,3,4); foreach $elem (@a) { return 'Hit!' if $elem == $a; } «ł› ¾Í–ƒq grep { $a == $_ } @b;
    • perl 5.10 ı “
    • ~~/æÄ
    • $a ~~ @b @b”Ì•$awm− xÕþßç•þáÞ|—¡ use 5.010; $a = 3; @b = (1,2,3,4); print "Hit!n" if $a ~~ @b;
    • Õþßç ¡„
    • $a ~~ %c îáÓ™”ô»Éß³¢—¡ use 5.010; $a = "Steve"; %c = ( "Steve" => "Jobs", "Bill" => "Gates" ); print "Hit!n" if $a ~~ %c;
    • oo ¡„
    • 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 ¡„
    • $a ~~ $d $a == $dºœ$a eq $dºœ ø|¶•́°©—¡
    • ̂̂̂¶µvó^ ¡„
    • @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するんだなぁ µµ̇
    • 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
    • =êœÀ”~~“ 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
    • ž O∼Œ¶z¶›–x¤
    • îáÓ™» 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}
    • Keysm›–© Value»∙q Øooœ|o $a = { "Steve" => "Jobs", "Bill" => "Gates" }; $b = { "Steve" => "Ballmer", "Bill" => "Gates" }; print "Smart match!n" if $a ~~ $b; # matchする!!
    • ∙µ∙µ |z¶›–x¤
    • H•Øo¬o¬ |z–ºº̃|z–
    • —ÞO•Øº }œ|o” ( id:moznion œ) oÚ¹ô½ßèïáË: ̃©̌” Èo |¤
    • The smartmatch family of features are now experimental
    • 5.18 g©¤" ‹O"¶)Ô•yß7—© ³°¶ozwooø„•¶›–|—o—|¤
    • ï
    • ǵ C›̃”$a ~~ @b»ƒ©¶ß•oo ∼“ Êq ” ofiv¡›xß|–a›–z− ∼– :ŸØgrep|–Ûe|—|łq
    • u|—o