develooper Front page | perl.perl6.users | Postings from November 2019

split to walk into an HoH ?

Thread Next
From:
Marc Chantreux
Date:
November 22, 2019 13:45
Subject:
split to walk into an HoH ?
Message ID:
20191122133933.GA28077@prometheus.u-strasbg.fr
hello people,

removing shell scripts is a good way to learn raku and compare.
today i want to replace this:

    fix () {
        awk -F, '{print $1"	"$2}' |
        sort -u                   |
        awk -F"	" '{
            if   (seen == $1) print "\t"$2;
            else { seen = $1; print $1 }
        }'
    }

and i got this:

    fix () perl6 -e '
        my %section;
        lines.map: {
            my ($s,$ss) = .split(",");
            %section{$s;$ss} = 1;
        }
        %section.keys.map:
            { .say for $_ , |%section{$_}.keys.map: {"\t$_"} }
    '

";" to walk in the hoh is really awesome but i don't know even know
from where i know it and what's the object underneath.
it isn't listed in the list of operators
(https://docs.perl6.org/language/operators).

i would like to know because it would be nice to make this block

        my ($s,$ss) = .split(",");
        %section{$s;$ss} = 1;

a one liner so i'm searching for something like

        %section{ .split(",").walkTheHash } = 1;

any help will be warmly welcome.

regards
marc

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About