in reply to Need to get hash of arrays
What Discipulus said:
You really should know all this by now. (sigh)Win8 Strawberry 5.8.9.5 (32) Fri 05/14/2021 4:48:55 C:\@Work\Perl\monks\workInProgress12 >perl use strict; use warnings; use autodie; use Data::Dump qw(dd); my $data = <<'EOD'; ColA | ColB | 500001| Network1| 500003| Network1| 500002| Network2| 500001| Network2| 500003| Network3| EOD open my $fh, '<', \$data; <$fh>; # ignore headings record/line my %hash4; while (<$fh>) { my ($k, $v) = map { (my $r = $_) =~ s{ \A \s+ | \s+ \z }{}xmsg; $r; } split /\s*\|\s*/ #splits $_ implicitly ; # print "\$k '$k' \$v '$v' \n"; # for debug push @{ $hash4{$k} }, $v; } dd \%hash4; close $fh; ^Z { 500001 => ["Network1", "Network2"], 500002 => ["Network2"], 500003 => ["Network1", "Network3"], }
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need to get hash of arrays
by haukex (Archbishop) on May 14, 2021 at 09:13 UTC | |
by chandantul (Scribe) on May 15, 2021 at 18:40 UTC | |
|
Re^2: Need to get hash of arrays
by LanX (Saint) on May 14, 2021 at 09:06 UTC | |
by AnomalousMonk (Archbishop) on May 14, 2021 at 10:47 UTC |