3 ms·
And interestingly enough Perl version can be almost the same, only without declarations: use POSIX; sub pk { print "$_[0]\n"; return ( \&pk, \&f
by acqq 16y ago
And interestingly enough Perl version can be almost the same, only without declarations:
use POSIX;
sub pk
{
print "$_[0]\n";
return ( \&pk, \&fabs )[ $_[0] / 1000 ]( $_[0] + 1 );
}
pk( 1 );
- onedognight 16y agoFWIW, there's no need to use a library. perl -e '($pk=sub { print "$_[0]\n"; ($pk, sub{}) [$_[0]/1000] ($_[0]+1) }) -> (1)'
- acqq 16y agoThanks. Of course (just for the readers who don't know) even much shorter Perl doesn't have "loops" (in C sense) fits the requirements and works: $,="\n"; print 1..1000 I don't know if it can be made shorter. My previous example was (also for the readers who don't know that) to demonstrate the "C inspired" features in Perl and almost 1-1 mapping to the C solution, minus declarations.