Nested templated data: Difference between revisions
Content added Content deleted
(added Factor) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: More concisely) |
||
Line 89: | Line 89: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2018.04.01}} |
{{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 |
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 feed (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>my @payloads = |
<lang perl6>say join "\n ", '##PAYLOADS:', |my @payloads = 'Payload#' X~ ^7; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
>; |
|||
sub template ($pattern) { @payloads[|$pattern] }; |
|||
for [ |
for [ |
||
Line 111: | Line 101: | ||
5),) |
5),) |
||
] { |
] { |
||
say |
say "\n Template: ", $_.perl; |
||
say "Data structure: { |
say "Data structure: { @payloads[|$_].perl }"; |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
<pre>##PAYLOADS: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Data structure: ((("Payload#1", "Payload#2"), ("Payload#3", "Payload#4", "Payload#1"), "Payload#5"),) |
Data structure: ((("Payload#1", "Payload#2"), ("Payload#3", "Payload#4", "Payload#1"), "Payload#5"),) |
||