on the inputuse v6; my $file = open 'scores'; my @names = $file.get.split(' '); my %matches; my %sets; for $file.lines -> $line { my ($pairing, $result) = $line.split(' | '); my ($p1, $p2) = $pairing.split(' vs '); my ($r1, $r2) = $result.split(':'); %sets{$p1} += $r1; %sets{$p2} += $r2; if $r1 > $r2 { %matches{$p1}++; } else { %matches{$p2}++; } } my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse +; for @sorted -> $n { say "$n has won %matches{$n} matches and %sets{$n} sets"; }
The following error is generated upon running the program:Beth Ana Charlie Dave Ana vs Dave | 3:0 Charlie vs Beth | 3:1 Ana vs Beth | 2:3 Dave vs Charlie | 3:0 Ana vs Charlie | 3:1 Beth vs Dave | 0:3
I've tried both retyping the code and directly copy-pasting from the book and the same results are observed. Has anyone successfully run the code in the book. I'm not sure if this is an issue specific to my build, or if there is a mistake in the code in the book. Thanks, DanaMethod 'split' not found for invocant of class '' in <anon> at line 12:type.p6 in main program body at line 1
In reply to using perl 6 book trying first example by reedx032
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |