ad switch vs perl6 doplnim:
http://dev.perl.org/perl6/rfc/22.html
ad clanek a reference na funkce.
Doplnim priklad v perlu:
sub nase_fce {
my $param = shift;
return $param + 1;
}
print nase_fce(5);
my $pointer_na_funkci = \&nase_fce;
print &$pointer_na_funkci(5);
# Nebo ...
# print &{$pointer_na_funkci}(5);
# print $pointer_na_funkci->(5);
ad clanek a priklad v perlu.
Vas priklad v perlu bych trosku upravil:
...
while (my $line = <infile>)) {
chomp $line;
next if $line =~ /^\s*$/;
...
sub my_grep($selector, *@list) {
given $selector {
when Rule { ... }
when Code { ... }
when Hash { ... }
# etc.
}
}
given want {
when Scalar {...} # called in scalar context
when List {...} # called in list context
when Lvalue {...} # expected to return an lvalue
when 2 {...} # expected to return two values
# ...
}
# The want function returns an object that contains information about the context in which the current block, closure, or subroutine was called.