Nested templated data: Difference between revisions

→‎{{header|Perl 6}}: More concisely
(added Factor)
(→‎{{header|Perl 6}}: More concisely)
Line 89:
=={{header|Perl 6}}==
{{works with|Rakudo|2018.04.01}}
Explicitly not using strings, using one data structure to fill in another. Since it ''isn't'' a string, the output format removes the newlines from the template; line feedsfeed aren(white space in general) isn't particularly significant in Perl 6 data structures. It does preserve the nesting though. In the second example, payload "buckets" that don't exist result in an undefined value being inserted; by default: Any.
<lang perl6>say join "\n ", '##PAYLOADS:', |my @payloads = <'Payload#' X~ ^7;
Payload#0
Payload#1
Payload#2
Payload#3
Payload#4
Payload#5
Payload#6
>;
 
sub template ($pattern) { @payloads[|$pattern] };
 
for [
Line 111 ⟶ 101:
5),)
] {
say '"\n Template: '", $_.perl;
say "Data structure: { template(@payloads[|$_)].perl }\n";
}</lang>
{{out}}
<pre>##PAYLOADS:
<pre> Template: $(((1, 2), (3, 4, 1), 5),)
Payload#0
Payload#1
Payload#2
Payload#3
Payload#4
Payload#5
Payload#6
 
<pre> Template: $(((1, 2), (3, 4, 1), 5),)
Data structure: ((("Payload#1", "Payload#2"), ("Payload#3", "Payload#4", "Payload#1"), "Payload#5"),)
 
10,351

edits