(sub {
print 1;
})();
sub {
print 1;
}();
I tried various ways, all are wrong...
# ------------------------------------------------------
# perl: filter array using given function
# ------------------------------------------------------
sub filter {
my ($arr1, $func) = @_;
my @arr2=();
foreach ( @{$arr1} ) {
push ( @arr2, $_ ) if $func->( $_ );
};
return @arr2;
}
# ------------------------------------------------------
# get files from dir
# ------------------------------------------------------
sub getFiles{
my ($p) = @_;
opendir my $dir, $p or die "Cannot open directory: $!";
my @files=readdir $dir;
closedir $dir;
#return files and directories that not ignored but not links
return filter \@files, (sub { my $f = $p.(shift);return ((-f $f) || (-d $f)) && (! -l $f) } );
}