Skip to content

Instantly share code, notes, and snippets.

@tyru
Created February 24, 2009 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/69346 to your computer and use it in GitHub Desktop.
Save tyru/69346 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode qw( encode );
use FileHandle;
use Getopt::Long;
use Perl6::Say;
use Pod::Usage;
say "closure test begin.";
say "-----------------------";
my @arrays = qw( hoge foo bar );
for( @arrays ) { say }
say "-----------------------";
my $clos = sub { push @arrays, shift };
$clos->( 'test' );
$clos->( 'aaa' );
for( @arrays ) { say }
say "-----------------------";
my $clos2 = sub { \@arrays };
sub {
my $clos = shift;
my $array_ref = $clos->();
while( my $_ = shift @$array_ref ) { say $_; }
}->( $clos2 );
say '--- say each @arrays ---';
for( @arrays ) { say }
say "-----------------------";
say "test end.";
__END__
=head1 NAME
=head1 SYNOPSIS
=head1 OPTIONS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment