.                                                                                      ..                          Perl.. ...
(          )(@yoshiyuki kondo)       Perl       PerlCasual #4 (2011/4/28)   2 / 44
(                  )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com/(@yoshiy...
(                    )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com/      ...
(                        )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com/  ...
(                        )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com/  ...
(                           )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com...
(                           )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com...
(                             )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.c...
(                           )       Twitter                 @yoshiyuki_kondo                 http://www.kondoyoshiyuki.com...
(@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)   ...
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...
use strict    use strict                                     OK    #!/usr/bin/perl    use strict;    use warnings;    $foo...
use strict    use strict                                            OK    #!/usr/bin/perl    use strict;    use warnings; ...
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...
warnings   use warnings   #!/usr/bin/perl   use strict;   use warnings;   my $foo = "10xxx";   my $x    = $foo + 5; # $foo...
(@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 ...
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 $_;}clos...
open                      Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) {    print $_;}clos...
open                      Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) {    print $_;}clos...
open                      Perlopen INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";while (<INPUT>) {    print $_;}clos...
open3                openopen my $input, "<", "mydata" (@yoshiyuki kondo)       Perl   PerlCasual #4 (2011/4/28)   11 / 44
open3                openopen my $input, "<", "mydata"             1                                 1                    ...
open3                openopen my $input, "<", "mydata"             1                                 1                    ...
open3                openopen my $input, "<", "mydata"             1                                 1                    ...
open                      open    1(@yoshiyuki kondo)     Perl       PerlCasual #4 (2011/4/28)   12 / 44
open                       open    1while (<$input>) { ......my $line = <$input>; (@yoshiyuki kondo)     Perl       PerlCa...
open                       open      1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen";   #p...
open                       open      1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen";   #p...
open                       open      1while (<$input>) { ......my $line = <$input>;print {$output} "This is a linen";   #p...
(@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 (...
C       $scaler_ref = $scalar;    #       $array_ref    = @array;   #       $hash_ref     = %hash;    #(@yoshiyuki kondo) ...
C       $scaler_ref = $scalar;       #       $array_ref    = @array;      #       $hash_ref     = %hash;       #       $fu...
C       $scaler_ref = $scalar;       #       $array_ref    = @array;      #       $hash_ref     = %hash;       #       $fu...
C       $scaler_ref = $scalar;       #       $array_ref    = @array;      #       $hash_ref     = %hash;       #       $fu...
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 10...
(@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   PerlC...
compute sum:sub compute_sum {    my ($aref) = @_; #           $aref    my $sum = 0;    foreach (@$aref) { #        $sum +=...
(@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                 PerlCasu...
ref                                  REF                                  SCALAR                                  ARRAY   ...
(@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)           Per...
print                                16                     CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo)           P...
print                                16                     CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo)           P...
(@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 (201...
${$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 (2...
->     $a->[3] $$a[3]     $h->{key} $$h{key}     $f->($param) &$f($param)            $a->[3]->[2]     (@yoshiyuki kondo)  ...
->     $a->[3] $$a[3]     $h->{key} $$h{key}     $f->($param) &$f($param)            $a->[3]->[2]     ->                  ...
$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) =...
compute summy @tmp_array = (1, 3, 5, 7, 9);print "Total: ", compute_sum(@tmp_array), "n";sub compute_sum {    my ($aref) =...
Perl                       (anonymous array)                      [] (@yoshiyuki kondo)        Perl            PerlCasual ...
Perl                       (anonymous array)                      []   )        5                                         ...
Perl                       (anonymous array)                      []   )        5                                         ...
compute sumprint "Total: ", compute_sum([1, 3, 5, 7, 9]), "n"; (@yoshiyuki kondo)    Perl       PerlCasual #4 (2011/4/28) ...
compute sumprint "Total: ", compute_sum([1, 3, 5, 7, 9]), "n";              (1, 2, 3)          [1, 2, 3] (@yoshiyuki kondo...
anonymoushash                     {}(@yoshiyuki kondo)        Perl   PerlCasual #4 (2011/4/28)   35 / 44
anonymoushash                     {}  )                              3$href = {one => 1, two => 2, three => 3};(@yoshiyuki...
=>=>         (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 ...
=>=>         (thick arrow)                     (Perl p121)        =>                               (            )        $...
=>=>         (thick arrow)                     (Perl p121)        =>                               (            )        $...
=>=>         (thick arrow)                     (Perl p121)        =>                               (            )        $...
=>=>         (thick arrow)                        (Perl p121)           =>                               (               )...
(                )my $userinfo = {         name => $name,                         uid => $uid,                         gid...
Data::Dumper                                ?    (@yoshiyuki kondo)   Perl       PerlCasual #4 (2011/4/28)   38 / 44
Data::Dumper                                          ?                                HASH(0x116360)    (@yoshiyuki kondo...
Data::Dumper                                                     ?                             HASH(0x116360)             ...
(   )                                    (              )(@yoshiyuki kondo)           Perl       PerlCasual #4 (2011/4/28)...
(   )Perl                                 anonymoussubroutine (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011...
(   )Perl                                 anonymoussubroutine        sub { ..... } (@yoshiyuki kondo)           Perl      ...
(   )Perl                                 anonymoussubroutine        sub { ..... } (@yoshiyuki kondo)           Perl      ...
(   )Perl                                 anonymoussubroutine        sub { ..... }                                        ...
(   )Perl                                 anonymoussubroutine        sub { ..... }                                        ...
(   )Perl                                     anonymoussubroutine        sub { ..... }                                    ...
(       )                         (closure)      ?                                 (my    )(@yoshiyuki kondo)             ...
(   )     adder:sub adder {    my ($increment) = @_;             #    return sub {        my ($x) = @_;        return $x +...
(    )        make counter:sub make_counter {    my ($counter) = @_;                  #    return sub {             return...
(   )(@yoshiyuki kondo)           Perl   PerlCasual #4 (2011/4/28)   44 / 44
(   )                                     use strictuse warnings (@yoshiyuki kondo)           Perl   PerlCasual #4 (2011/4...
Upcoming SlideShare
Loading in …5
×

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

23,311 views

Published on

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

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

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

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

      前半: http://youtu.be/kLt2aYN7UYE
      後半: http://youtu.be/xVC9pqCe8cE
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
23,311
On SlideShare
0
From Embeds
0
Number of Embeds
4,099
Actions
Shares
0
Downloads
123
Comments
2
Likes
24
Embeds 0
No embeds

No notes for slide

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

  1. 1. . .. Perl.. . . @yoshiyuki kondo PerlCasual #4 (2011/4/28) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 1 / 44
  2. 2. ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  3. 3. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  4. 4. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  5. 5. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  6. 6. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  7. 7. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  8. 8. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : : Emacs(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  9. 9. ( ) Twitter @yoshiyuki_kondo http://www.kondoyoshiyuki.com/ Perl Perl C Java : : Emacs :(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 2 / 44
  10. 10. ( ) 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
  11. 11. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 3 / 44
  12. 12. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
  13. 13. Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
  14. 14. Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
  15. 15. Perl Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 4 / 44
  16. 16. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
  17. 17. use strictuse warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
  18. 18. use strict use warnings#!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 5 / 44
  19. 19. use strict (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
  20. 20. use strict use strict OK (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 6 / 44
  21. 21. 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
  22. 22. 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
  23. 23. warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
  24. 24. warnings use warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 7 / 44
  25. 25. 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
  26. 26. 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
  27. 27. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
  28. 28. #!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
  29. 29. #!/usr/bin/perluse strict;use warnings; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
  30. 30. #!/usr/bin/perluse strict;use warnings; !! (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 8 / 44
  31. 31. open open(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 9 / 44
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. 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
  36. 36. open3 openopen my $input, "<", "mydata" (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
  37. 37. open3 openopen my $input, "<", "mydata" 1 1 my (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
  38. 38. open3 openopen my $input, "<", "mydata" 1 1 my 2 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
  39. 39. open3 openopen my $input, "<", "mydata" 1 1 my 2 3 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 11 / 44
  40. 40. open open 1(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
  41. 41. open open 1while (<$input>) { ......my $line = <$input>; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 12 / 44
  42. 42. 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
  43. 43. 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
  44. 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
  45. 45. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 13 / 44
  46. 46. reference(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
  47. 47. referenceC(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
  48. 48. referenceC etc.(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 14 / 44
  49. 49. C $scaler_ref = $scalar; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
  50. 50. C $scaler_ref = $scalar; # $array_ref = @array; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
  51. 51. C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
  52. 52. C $scaler_ref = $scalar; # $array_ref = @array; # $hash_ref = %hash; # $func_ref = &function; #(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 15 / 44
  53. 53. 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
  54. 54. 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
  55. 55. dereference(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 16 / 44
  56. 56. dereferencePerl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 16 / 44
  57. 57. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
  58. 58. $sref = $x; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
  59. 59. $sref = $x;$a = $$ref; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 17 / 44
  60. 60. $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
  61. 61. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
  62. 62. $array_ref = @array; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
  63. 63. $array_ref = @array;@s = @$array_ref; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
  64. 64. $array_ref = @array;@s = @$array_ref;$$array_ref[10] = 10; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
  65. 65. $array_ref = @array;@s = @$array_ref;$$array_ref[10] = 10;foreachforeach (@$array_ref) { (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 18 / 44
  66. 66. 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
  67. 67. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
  68. 68. $href = %h; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
  69. 69. $href = %h;$x = $$href{’a’}; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
  70. 70. $href = %h;$x = $$href{’a’};keysforeach (keys %$href) { (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 20 / 44
  71. 71. (coderef)(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
  72. 72. (coderef)$fref = &func; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
  73. 73. (coderef)$fref = &func;&$fref($param); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 21 / 44
  74. 74. $aref = @array;$$aref = 10; Not a SCALAR reference at - line 7.(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 22 / 44
  75. 75. ref REF SCALAR ARRAY HASH CODE GLOB (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 23 / 44
  76. 76. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
  77. 77. print(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
  78. 78. print 16 CODE(0xbb5b48), HASH(0xbb59f8)(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
  79. 79. print 16 CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
  80. 80. print 16 CODE(0xbb5b48), HASH(0xbb59f8)eq(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 24 / 44
  81. 81. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
  82. 82. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
  83. 83. ${$sref}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
  84. 84. ${$sref}@{&get_array_ref()}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
  85. 85. ${$sref}@{&get_array_ref()}${$a[2]} $$a[2] $$a[2] ${$a}[2](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 25 / 44
  86. 86. ${$a[2]} $$a[2] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 26 / 44
  87. 87. -> $a->[3] $$a[3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
  88. 88. -> $a->[3] $$a[3] $h->{key} $$h{key} (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
  89. 89. -> $a->[3] $$a[3] $h->{key} $$h{key} $f->($param) &$f($param) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 27 / 44
  90. 90. -> $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
  91. 91. -> $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
  92. 92. $a[3][2][5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
  93. 93. $a[3][2][5] $a[3]->[2]->[5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
  94. 94. $a[3][2][5] $a[3]->[2]->[5]$a->[3][2][5](@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 28 / 44
  95. 95. $a[2][1] $a->[2][1] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 29 / 44
  96. 96. Perl (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
  97. 97. Perl$a[2][3] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
  98. 98. Perl$a[2][3]$a[2][1] = 100 (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 30 / 44
  99. 99. (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 31 / 44
  100. 100. 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
  101. 101. 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
  102. 102. Perl (anonymous array) [] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
  103. 103. Perl (anonymous array) [] ) 5 $aref $aref = [1, 2, 3, 4, 5] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
  104. 104. Perl (anonymous array) [] ) 5 $aref $aref = [1, 2, 3, 4, 5] (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 33 / 44
  105. 105. compute sumprint "Total: ", compute_sum([1, 3, 5, 7, 9]), "n"; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 34 / 44
  106. 106. 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
  107. 107. anonymoushash {}(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 35 / 44
  108. 108. anonymoushash {} ) 3$href = {one => 1, two => 2, three => 3};(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 35 / 44
  109. 109. =>=> (thick arrow) (Perl p121) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
  110. 110. =>=> (thick arrow) (Perl p121) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
  111. 111. =>=> (thick arrow) (Perl p121) => ( ) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
  112. 112. =>=> (thick arrow) (Perl p121) => ( ) $href = {one => 1, two => 2, three => 3}; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
  113. 113. =>=> (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
  114. 114. =>=> (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
  115. 115. =>=> (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
  116. 116. ( )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
  117. 117. Data::Dumper ? (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 38 / 44
  118. 118. Data::Dumper ? HASH(0x116360) (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 38 / 44
  119. 119. 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
  120. 120. ( ) ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 39 / 44
  121. 121. ( )Perl anonymoussubroutine (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  122. 122. ( )Perl anonymoussubroutine sub { ..... } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  123. 123. ( )Perl anonymoussubroutine sub { ..... } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  124. 124. ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; } (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  125. 125. ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; }&$fref("world"); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  126. 126. ( )Perl anonymoussubroutine sub { ..... } fref$fref = sub { print "Hello, $_[0]n"; }&$fref("world");-> ( )$fref->("world"); (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 40 / 44
  127. 127. ( ) (closure) ? (my )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 41 / 44
  128. 128. ( ) 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
  129. 129. ( ) 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
  130. 130. ( )(@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 44 / 44
  131. 131. ( ) use strictuse warnings (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 44 / 44

×