[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
SlideShare a Scribd company logo
.
                                                                                      .
.
                          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 strict
use warnings




 (@yoshiyuki kondo)   Perl    PerlCasual #4 (2011/4/28)   5 / 44
use strict
 use warnings

#!/usr/bin/perl

use 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/perl

use strict;
use warnings;




   (@yoshiyuki kondo)   Perl   PerlCasual #4 (2011/4/28)   8 / 44
#!/usr/bin/perl

use strict;
use warnings;




   (@yoshiyuki kondo)   Perl   PerlCasual #4 (2011/4/28)   8 / 44
#!/usr/bin/perl

use 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




                      Perl
open INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";
while (<INPUT>) {
    print $_;
}
close INPUT;




 (@yoshiyuki kondo)            Perl                 PerlCasual #4 (2011/4/28)   10 / 44
open




                      Perl
open INPUT, "<mydata" or die "Cannot open ’mydata’: $!n";
while (<INPUT>) {
    print $_;
}
close INPUT;




 (@yoshiyuki kondo)            Perl                 PerlCasual #4 (2011/4/28)   10 / 44
open




                      Perl
open 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




                      Perl
open 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
open




3                open
open my $input, "<", "mydata"




 (@yoshiyuki kondo)       Perl   PerlCasual #4 (2011/4/28)   11 / 44
open




3                open
open my $input, "<", "mydata"
             1

                                 1                      my




 (@yoshiyuki kondo)       Perl       PerlCasual #4 (2011/4/28)   11 / 44
open




3                open
open my $input, "<", "mydata"
             1

                                 1                      my

             2




 (@yoshiyuki kondo)       Perl       PerlCasual #4 (2011/4/28)   11 / 44
open




3                open
open 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    1



while (<$input>) { ......
my $line = <$input>;




 (@yoshiyuki kondo)     Perl       PerlCasual #4 (2011/4/28)   12 / 44
open




                       open      1



while (<$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      1



while (<$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      1



while (<$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
reference


C




(@yoshiyuki kondo)      Perl     PerlCasual #4 (2011/4/28)   14 / 44
reference


C


                                 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
dereference

Perl




 (@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; #                               $sref

print "$$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;
foreach
foreach (@$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’};
keys
foreach (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 sum
my @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 sum
my @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 sum
print "Total: ", compute_sum([1, 3, 5, 7, 9]), "n";




 (@yoshiyuki kondo)    Perl       PerlCasual #4 (2011/4/28)   34 / 44
compute sum
print "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
anonymous
hash
                     {}




(@yoshiyuki kondo)        Perl   PerlCasual #4 (2011/4/28)   35 / 44
anonymous
hash
                     {}




  )                              3

$href = { 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 = { 1, two => 2, three => 3};




 (@yoshiyuki kondo)   Perl            PerlCasual #4 (2011/4/28)   36 / 44
=>
=>         (thick arrow)                     (
Perl p121)

        =>                               (
            )


        $href = { 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 = { 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 = { 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                                 anonymous
subroutine




 (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011/4/28)   40 / 44
(   )




Perl                                 anonymous
subroutine
        sub { ..... }




 (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011/4/28)   40 / 44
(   )




Perl                                 anonymous
subroutine
        sub { ..... }




 (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011/4/28)   40 / 44
(   )




Perl                                 anonymous
subroutine
        sub { ..... }


                                           fref
$fref = sub { print "Hello, $_[0]n"; }




 (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011/4/28)   40 / 44
(   )




Perl                                 anonymous
subroutine
        sub { ..... }


                                           fref
$fref = sub { print "Hello, $_[0]n"; }

&$fref("world");




 (@yoshiyuki kondo)           Perl        PerlCasual #4 (2011/4/28)   40 / 44
(   )




Perl                                     anonymous
subroutine
        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);               # 1
my $add20 = adder(20);             # 20

print $add1->(10), "n";             # 11
print $add20->(10), "n";            # 30
print $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);   #                  0
my $bar = make_counter(100); #                  100

print   $foo->(),        "n";     #   1
print   $bar->(),        "n";     #   101
print   $bar->(),        "n";     #   102
print   $foo->(),        "n";     #   2
print   $bar->(),        "n";     #   103
print   $foo->(),        "n";     #   3

        (@yoshiyuki kondo)              Perl          PerlCasual #4 (2011/4/28)   43 / 44
(   )




(@yoshiyuki kondo)           Perl   PerlCasual #4 (2011/4/28)   44 / 44
(   )




                                     use strict
use warnings




 (@yoshiyuki kondo)           Perl   PerlCasual #4 (2011/4/28)   44 / 44

More Related Content

Recently uploaded (20)

[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
 
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-StoryRevolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
ssuser52ad5e
 
UiPath Automation Developer Associate Training Series 2025 - Session 1
UiPath Automation Developer Associate Training Series 2025 - Session 1UiPath Automation Developer Associate Training Series 2025 - Session 1
UiPath Automation Developer Associate Training Series 2025 - Session 1
DianaGray10
 
FinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptxFinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptx
Tracxn
 
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar PatturajInside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
ScyllaDB
 
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
 
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarterQ4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
MariaBarbaraPaglinaw
 
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
 
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
 
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
 
The Future of Repair: Transparent and Incremental by Botond Dénes
The Future of Repair: Transparent and Incremental by Botond DénesThe Future of Repair: Transparent and Incremental by Botond Dénes
The Future of Repair: Transparent and Incremental by Botond Dénes
ScyllaDB
 
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
 
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
 
A Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin EngineeringA Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin Engineering
Daniel Lehner
 
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
 
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
Unlock AI Creativity: Image Generation with DALL·E
Unlock AI Creativity: Image Generation with DALL·EUnlock AI Creativity: Image Generation with DALL·E
Unlock AI Creativity: Image Generation with DALL·E
Expeed Software
 
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
 
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
 
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
Tsuyoshi Hirayama
 
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
 
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-StoryRevolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
ssuser52ad5e
 
UiPath Automation Developer Associate Training Series 2025 - Session 1
UiPath Automation Developer Associate Training Series 2025 - Session 1UiPath Automation Developer Associate Training Series 2025 - Session 1
UiPath Automation Developer Associate Training Series 2025 - Session 1
DianaGray10
 
FinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptxFinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptx
Tracxn
 
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar PatturajInside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
Inside Freshworks' Migration from Cassandra to ScyllaDB by Premkumar Patturaj
ScyllaDB
 
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
 
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarterQ4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
Q4_TLE-7-Lesson-6-Week-6.pptx 4th quarter
MariaBarbaraPaglinaw
 
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
 
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
 
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
 
The Future of Repair: Transparent and Incremental by Botond Dénes
The Future of Repair: Transparent and Incremental by Botond DénesThe Future of Repair: Transparent and Incremental by Botond Dénes
The Future of Repair: Transparent and Incremental by Botond Dénes
ScyllaDB
 
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
 
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
 
A Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin EngineeringA Framework for Model-Driven Digital Twin Engineering
A Framework for Model-Driven Digital Twin Engineering
Daniel Lehner
 
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
 
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
Unlock AI Creativity: Image Generation with DALL·E
Unlock AI Creativity: Image Generation with DALL·EUnlock AI Creativity: Image Generation with DALL·E
Unlock AI Creativity: Image Generation with DALL·E
Expeed Software
 
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
 
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
 
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (平山毅)
Tsuyoshi Hirayama
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

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

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