Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Nested-templated-data/Perl/nested-templated-data-1.pl
Normal file
16
Task/Nested-templated-data/Perl/nested-templated-data-1.pl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
sub fulfill {
|
||||
my @payloads;
|
||||
push @payloads, 'Payload#' . $_ for 0..5;
|
||||
my @result;
|
||||
push @result, ref $_ eq 'ARRAY' ? [@payloads[@$_]] : @payloads[$_] for @{@_[0]};
|
||||
return [@result];
|
||||
}
|
||||
|
||||
sub formatted {
|
||||
my $result;
|
||||
$result .= ref $_ eq 'ARRAY' ? '[ "'. join('", "', @$_) . '" ], ' : qq{"$_"} for @{@_[0]};
|
||||
return '[ ' . $result . " ]\n";
|
||||
}
|
||||
|
||||
print formatted fulfill( [[1,2], [ 3,4,1], 5] );
|
||||
print formatted fulfill( [[1,2], [10,4,1], 5] );
|
||||
22
Task/Nested-templated-data/Perl/nested-templated-data-2.pl
Normal file
22
Task/Nested-templated-data/Perl/nested-templated-data-2.pl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Nested_templated_data
|
||||
use warnings;
|
||||
use Data::Dump 'dd';
|
||||
|
||||
my $t = [
|
||||
[[1, 2],
|
||||
[3, 4, 1],
|
||||
5]];
|
||||
|
||||
my $p = [ map "Payload#$_", 0 .. 6 ];
|
||||
dd { 'template' => $t, 'payload' => $p };
|
||||
|
||||
my $output = filltemplate( $t, $p );
|
||||
dd { 'output' => $output };
|
||||
|
||||
sub filltemplate
|
||||
{
|
||||
my ($t, $p) = @_;
|
||||
return ref $t eq 'ARRAY' ? [ map filltemplate($_, $p), @$t ] : $p->[$t];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue