• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Perl中級者への道 (近藤 嘉雪, at PerlCasual #4)
 

Perl中級者への道 (近藤 嘉雪, at PerlCasual #4)

on

  • 21,403 views

PerlCasual #4 (2011/4/28, 池袋ジュンク堂)で行ったトークのスライドです。

PerlCasual #4 (2011/4/28, 池袋ジュンク堂)で行ったトークのスライドです。
動画をYouTubeで公開しているので、あわせてご覧ください。http://youtu.be/kLt2aYN7UYE, http://youtu.be/xVC9pqCe8cE

Statistics

Views

Total Views
21,403
Views on SlideShare
17,942
Embed Views
3,461

Actions

Likes
20
Downloads
108
Comments
2

15 Embeds 3,461

http://blog.livedoor.jp 1801
http://www.kondoyoshiyuki.com 1024
http://chalow.net 342
http://blog.kondoyoshiyuki.com 229
http://www.slideshare.net 19
http://s.deeeki.com 9
http://webcache.googleusercontent.com 9
http://paper.li 9
url_unknown 7
http://twitter.com 4
https://twitter.com 2
https://si0.twimg.com 2
https://www.google.co.jp 2
http://us-w1.rockmelt.com 1
http://translate.googleusercontent.com 1
More...

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

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • スライド10~12ページ目(PDFで32~44ページ目)の説明で,ファイルハンドルと
    変数の名前をDATA,$dataから,INPUT,$input, $outputに変更しました。
    (小飼弾氏の指摘による)
    Are you sure you want to
    Your message goes here
    Processing…
  • PerlCasual #4 「本屋で語るPerlプログラミングTips」 (2011/4/28, 池袋ジュンク堂)で行ったトーク「Perl中級者への道」のスライドです。

    Perlの初級者から一歩踏み出して,中級者になるための知識――リファレンス,コードレフ(クロージャ)など――を紹介します。また,Perlスクリプトでよく使われる-慣用句的な表現(イディオム)も紹介します。

    動画をYouTubeで公開しています。あわせてご覧ください。

      前半: http://youtu.be/kLt2aYN7UYE
      後半: http://youtu.be/xVC9pqCe8cE
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Perl中級者への道 (近藤 嘉雪, at PerlCasual #4) Perl中級者への道 (近藤 嘉雪, at PerlCasual #4) Presentation Transcript

    • . .. Perl.. . . @yoshiyuki kondo PerlCasual #4 (2011/4/28) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 1 / 44
    • ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : : Emacs(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : : Emacs :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : : Emacs : T-Code (2 )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 3 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
    • Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
    • Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
    • Perl Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
    • use strictuse warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
    • use strict use warnings#!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
    • use strict (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
    • use strict use strict OK (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
    • use strict use strict OK #!/usr/bin/perl use strict; use warnings; $foo = 10; # $foo my $bar = 2; print $foo, "n"; # $foo print $bar, "n"; print $x, "n"; # $x (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
    • use strict use strict OK #!/usr/bin/perl use strict; use warnings; $foo = 10; # $foo my $bar = 2; print $foo, "n"; # $foo print $bar, "n"; print $x, "n"; # $x Global symbol "$foo" requires explicit package name at .... (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
    • warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
    • warnings use warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
    • warnings use warnings #!/usr/bin/perl use strict; use warnings; my $foo = "10xxx"; my $x = $foo + 5; # $foo my $bar; print "$barn"; # $bar undef (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
    • warnings use warnings #!/usr/bin/perl use strict; use warnings; my $foo = "10xxx"; my $x = $foo + 5; # $foo my $bar; print "$barn"; # $bar undef Argument "10xxx" isn’t numeric in addition (+) at .... Use of uninitialized value $bar in concatenation (.) or string at .... (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
    • #!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
    • #!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
    • #!/usr/bin/perluse strict;use warnings; !! (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
    • open open(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 9 / 44
    • open Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) { print $_;}close INPUT; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 10 / 44
    • open Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) { print $_;}close INPUT; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 10 / 44
    • open Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) { print $_;}close INPUT;open my $input, "<", "mydata" or die "Cannot open ’mydata’: $!n";while (<$input>) { print $_;}close $input; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 10 / 44
    • open Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) { print $_;}close INPUT;open my $input, "<", "mydata" or die "Cannot open ’mydata’: $!n";while (<$input>) { print $_;}close $input; $input (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 10 / 44
    • open3 openopen my $input, "<", "mydata" (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
    • open3 openopen my $input, "<", "mydata" 1 1 my (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
    • open3 openopen my $input, "<", "mydata" 1 1 my 2 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
    • open3 openopen my $input, "<", "mydata" 1 1 my 2 3 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
    • open open 1(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
    • open open 1while (<$input>) { ......my $line = <$input>; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
    • open open 1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen"; #print $output "This is a linen"; # (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
    • open open 1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen"; #print $output "This is a linen"; #print $output, "This is a linen"; # (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
    • open open 1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen"; #print $output "This is a linen"; #print $output, "This is a linen"; #IO::File$output->print("This is a line datan"); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 13 / 44
    • reference(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
    • referenceC(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
    • referenceC etc.(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
    • C $scaler_ref = $scalar; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • C $scaler_ref = $scalar; # $array_ref = @array; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; # $func_ref = &function; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; # $func_ref = &function; # $glob_ref = *STDOUT; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; # $func_ref = &function; # $glob_ref = *STDOUT; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
    • dereference(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 16 / 44
    • dereferencePerl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 16 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
    • $sref = $x; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
    • $sref = $x;$a = $$ref; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
    • $sref = $x;$a = $$ref;my $x = 100;my $sref = $x; # $srefprint "$$sref $xn"; # 100 100$$sref += 5;print "$$sref $xn"; # 105 105 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
    • $array_ref = @array; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
    • $array_ref = @array;@s = @$array_ref; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
    • $array_ref = @array;@s = @$array_ref;$$array_ref[10] = 10; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
    • $array_ref = @array;@s = @$array_ref;$$array_ref[10] = 10;foreachforeach (@$array_ref) { (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
    • compute sum:sub compute_sum { my ($aref) = @_; # $aref my $sum = 0; foreach (@$aref) { # $sum += $_; } return $sum;} (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 19 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
    • $href = %h; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
    • $href = %h;$x = $$href{’a’}; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
    • $href = %h;$x = $$href{’a’};keysforeach (keys %$href) { (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
    • (coderef)(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
    • (coderef)$fref = &func; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
    • (coderef)$fref = &func;&$fref($param); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
    • $aref = @array;$$aref = 10; Not a SCALAR reference at - line 7.(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 22 / 44
    • ref REF SCALAR ARRAY HASH CODE GLOB (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 23 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
    • print(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
    • print 16 CODE(0xbb5b48), HASH(0xbb59f8)(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
    • print 16 CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
    • print 16 CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
    • ${$sref}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
    • ${$sref}@{&get_array_ref()}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
    • ${$sref}@{&get_array_ref()}${$a[2]} $$a[2] $$a[2] ${$a}[2](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
    • ${$a[2]} $$a[2] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 26 / 44
    • -> $a->[3] $$a[3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
    • -> $a->[3] $$a[3] $h->{key} $$h{key} (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
    • -> $a->[3] $$a[3] $h->{key} $$h{key} $f->($param) &$f($param) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
    • -> $a->[3] $$a[3] $h->{key} $$h{key} $f->($param) &$f($param) $a->[3]->[2] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
    • -> $a->[3] $$a[3] $h->{key} $$h{key} $f->($param) &$f($param) $a->[3]->[2] -> [],{} () -> $a->[3]->[2] $a->[2][3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
    • $a[3][2][5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
    • $a[3][2][5] $a[3]->[2]->[5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
    • $a[3][2][5] $a[3]->[2]->[5]$a->[3][2][5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
    • $a[2][1] $a->[2][1] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 29 / 44
    • Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
    • Perl$a[2][3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
    • Perl$a[2][3]$a[2][1] = 100 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
    • (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 31 / 44
    • compute summy @tmp_array = (1, 3, 5, 7, 9);print "Total: ", compute_sum(@tmp_array), "n";sub compute_sum { my ($aref) = @_; my $sum = 0; foreach (@$aref) { $sum += $_; } return $sum;} (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 32 / 44
    • compute summy @tmp_array = (1, 3, 5, 7, 9);print "Total: ", compute_sum(@tmp_array), "n";sub compute_sum { my ($aref) = @_; my $sum = 0; foreach (@$aref) { $sum += $_; } return $sum;} @tmp array (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 32 / 44
    • Perl (anonymous array) [] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
    • Perl (anonymous array) [] ) 5 $aref $aref = [1, 2, 3, 4, 5] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
    • Perl (anonymous array) [] ) 5 $aref $aref = [1, 2, 3, 4, 5] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
    • compute sumprint "Total: ", compute_sum([1, 3, 5, 7, 9]), "n"; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 34 / 44
    • compute sumprint "Total: ", compute_sum([1, 3, 5, 7, 9]), "n"; (1, 2, 3) [1, 2, 3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 34 / 44
    • anonymoushash {}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 35 / 44
    • anonymoushash {} ) 3$href = {one => 1, two => 2, three => 3};(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 35 / 44
    • =>=> (thick arrow) (Perl p121) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) => ( ) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) => ( ) $href = {one => 1, two => 2, three => 3}; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) => ( ) $href = {one => 1, two => 2, three => 3}; $href = {’one’, 1, ’two’, 2, ’three’, 3 }; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) => ( ) $href = {one => 1, two => 2, three => 3}; $href = {’one’, 1, ’two’, 2, ’three’, 3 }; => (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • =>=> (thick arrow) (Perl p121) => ( ) $href = {one => 1, two => 2, three => 3}; $href = {’one’, 1, ’two’, 2, ’three’, 3 }; =>( ) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
    • ( )my $userinfo = { name => $name, uid => $uid, gid => [1, 200, 201, 203], env => { HOME => $ENV{HOME}, TERM => "VT100" } }; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 37 / 44
    • Data::Dumper ? (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 38 / 44
    • Data::Dumper ? HASH(0x116360) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 38 / 44
    • Data::Dumper ? HASH(0x116360) Data::Dumper $VAR1 = { ’uid’ => 1001, ’env’ => { ’HOME’ => ’/home/cond’, ’TERM’ => ’VT100’ }, ’name’ => ’John’, ’gid’ => [ 1, 200, 201, 203 ] }; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 38 / 44
    • ( ) ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 39 / 44
    • ( )Perl anonymoussubroutine (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( )Perl anonymoussubroutine sub { ..... } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( )Perl anonymoussubroutine sub { ..... } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; }&$fref("world"); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; }&$fref("world");-> ( )$fref->("world"); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
    • ( ) (closure) ? (my )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 41 / 44
    • ( ) adder:sub adder { my ($increment) = @_; # return sub { my ($x) = @_; return $x + $increment; }}my $add1 = adder(1); # 1my $add20 = adder(20); # 20print $add1->(10), "n"; # 11print $add20->(10), "n"; # 30print $add1->(30), "n"; # 31 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 42 / 44
    • ( ) make counter:sub make_counter { my ($counter) = @_; # return sub { return ++$counter };}my $foo = make_counter(0); # 0my $bar = make_counter(100); # 100print $foo->(), "n"; # 1print $bar->(), "n"; # 101print $bar->(), "n"; # 102print $foo->(), "n"; # 2print $bar->(), "n"; # 103print $foo->(), "n"; # 3 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 43 / 44
    • ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 44 / 44
    • ( ) use strictuse warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 44 / 44