SlideShare a Scribd company logo
1 of 131
Download to read offline
.
                                                                                      .
.
                          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 = {one => 1, two => 2, three => 3};




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




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




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

        =>                      (
            )




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

        =>                               (
            )


        $href = {one => 1, two => 2, three => 3};




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

        =>                               (
            )


        $href = {one => 1, two => 2, three => 3};

        $href = {’one’, 1, ’two’, 2, ’three’, 3 };




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

        =>                               (
            )


        $href = {one => 1, two => 2, three => 3};

        $href = {’one’, 1, ’two’, 2, ’three’, 3 };


                      =>

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

           =>                               (
               )


           $href = {one => 1, two => 2, three => 3};

           $href = {’one’, 1, ’two’, 2, ’three’, 3 };


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

my $userinfo = {         name => $name,
                         uid => $uid,
                         gid => [1, 200, 201, 203],
                         env => {
                               HOME => $ENV{HOME},
                               TERM => "VT100" } };




    (@yoshiyuki kondo)   Perl           PerlCasual #4 (2011/4/28)   37 / 44
Data::Dumper


                                ?




    (@yoshiyuki kondo)   Perl       PerlCasual #4 (2011/4/28)   38 / 44
Data::Dumper


                                          ?
                                HASH(0x116360)




    (@yoshiyuki kondo)   Perl                 PerlCasual #4 (2011/4/28)   38 / 44
Data::Dumper


                                                     ?
                             HASH(0x116360)
                 Data::Dumper
   $VAR1 = {
               ’uid’ => 1001,
               ’env’ => {
                           ’HOME’ => ’/home/cond’,
                           ’TERM’ => ’VT100’
                        },
               ’name’ => ’John’,
               ’gid’ => [
                           1,
                           200,
                           201,
                           203
                        ]
             };

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




                                    (              )




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




Perl                                 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

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

Featured

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 2024Neil 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 2024Albert 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 InsightsKurio // 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 2024Search 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 summarySpeakerHub
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit 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 managementMindGenius
 
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 WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

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
 
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)
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
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
 
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...
 
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...
 
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
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

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 = {one => 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 = {one => 1, two => 2, three => 3}; (@yoshiyuki kondo) Perl PerlCasual #4 (2011/4/28) 36 / 44
  • 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. => => (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. => => (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. ( ) 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