fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4.  
  5. sub f {
  6. my $n = 0;
  7. return sub {
  8. @_ < 1 ? $n++ : [ map{ __SUB__->(@_[1 .. $#_]) } (1 .. $_[0]) ]
  9. }->(@_);
  10. }
  11.  
  12. use Data::Dumper;
  13. local $Data::Dumper::Terse = 1;
  14. local $Data::Dumper::Indent = 0;
  15.  
  16. my $aa = f(2, 3, 4);
  17. say Dumper($aa);
  18. say $aa->[1][2][3];
  19.  
Success #stdin #stdout 0.02s 5172KB
stdin
Standard input is empty
stdout
[[[0,1,2,3],[4,5,6,7],[8,9,10,11]],[[12,13,14,15],[16,17,18,19],[20,21,22,23]]]
23