List::Haystack - A immutable list utility to find and count element
Perl5ã®è©±é¡ã§ãï¼List::Haystackã¨ãããã®ãæ¸ãã¾ããï¼CPANã«ãã¢ãããã¼ããã¦ãã¾ãï¼
çµç·¯ã¨ãã¦ã¯ä»¥ä¸ï¼
Perlï¼immutableãªæãã§ï¼List (Array) ä¸ããè¦ç´ ãfindãããï¼åºç¾åæ°ãåãã¢ã¸ã¥ã¼ã«ã£ã¦åå¨ãã¦ãããã§ããã£ã
— ãããªãã¯ã¤ã¡ã¼ã¸ãæªã (@moznion) 2017å¹´6æ20æ¥
`my $haystack = List::XXX->new([...]); $haystack->find('java');` ã¿ãããªæãã§ï¼ `$haystack` ã¯immutableãªåå¨ã§é½åº¦ã¹ãã£ã³ããªãã§ã¯ããè¿ãã¦ãããï¼ã¿ãããª
— ãããªãã¯ã¤ã¡ã¼ã¸ãæªã (@moznion) 2017å¹´6æ20æ¥
ã¨ãããã®ã欲ããã£ãã®ã§ãï¼Listå ã®è¦ç´ æ¤ç´¢ã«ã¤ãã¦ï¼Immutableã«å¦çãããã + lazilyã«å¦çãããï¼ã¿ãããªã¢ããã¼ã·ã§ã³ã§ãï¼
åå¥ã®ä½¿ãæ¹ã¨ãã¦ã¯podãèªãã§ãããã¨ãã¦ï¼ä¾ãã°ä»¥ä¸ã®ããã«æ¸ãã ãã§ã·ã§ã¼ã¯ã¹ãã¢ã®ã¯ã¼ãã«ã¦ã³ããªãã¦ã®ãæã£åãæ©ãæ¸ããããã§ãï¼çãã大å¦ã¨ãã§ããã¾ããã§ãããï¼åã¯ããã¾ããã§ããï¼
use LWP::UserAgent (); use List::Haystack; use Data::Dumper; my $response = LWP::UserAgent->new->get('https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt'); my $txt = $response->decoded_content; my $words = [grep { $_ } split /[^a-zA-Z0-9]/, $txt]; # XXX: Sloppy word separation!!! my $haystack = List::Haystack->new($words); print Dumper($haystack->haystack);
ã¾ãããããã®ã£ã¦perlã ã¨Hashã¨ãã§ç°¡åã«æ¸ãããã§å¥ã«ã¢ã¸ã¥ã¼ã«ã«ããªãã¦ãâ¦â¦ã¨è¨ãæãã§ããï¼ã¢ãããã¯ã«æ¸ãã¨åããããªå¦çãéæã«æ£ãã°ã£ã¦ãã¾ããã¡ã§ç²¾ç¥è¡çä¸è¯ããªãã£ãã®ã§ä¸ä¸ã¢ã¸ã¥ã¼ã«ã«ããããã次第ã§ãï¼ãã¨lazilyãªconstructionã欲ããã£ãã®ã§ï¼
ãå©ç¨ãã ããã¾ãï¼