|
|
|
|
|
by vram22
2743 days ago
|
|
>In contrast to Perl5, Perl6 makes it far easier to avoid accidental spaghetti and does so without sacrificing any of the linguistic expressiveness that makes Perl generally so useful. Can you give some examples of that point, w.r.t. Perl6? |
|
Earlier this year at perlmonks (perhaps the top resource along with stackoverflow for experienced perl folk answering questions) a poster wanted solutions to a fairly basic operation:[1]
> I need a function which will filter a nested hash, removing any fields I'm not interested in.
Their test data had a source that began:
and a filter that began: After a few days the person who asked the question summarized the community's P5 answers.[2]The first one listed (slightly trimmed):
(This appears to include a modicum of input validation.)Here was my P6 answer, including the call to invoke the routine (which I omitted from the P5):[3]
Even though this uses a parallel operation which will one day optionally be automatically mapped to multiple cores to run faster, I'm pretty sure this is currently slower than the P5 solutions.And I didn't bother with any validation that it was indeed being passed a nested hash.
But it makes a point. While P6 can typically do similar things to P5, it often turns out easier to do many things at a much higher level, which leads to less spaghetti.
----
[1] https://www.perlmonks.org/?node_id=1215517
[2] https://www.perlmonks.org/?node_id=1215736
[3] https://www.perlmonks.org/?node_id=1216274