http://www.perlmonks.org?node_id=11132570


in reply to Re: Need to get hash of arrays
in thread Need to get hash of arrays

Or with Text::CSV/Text::CSV_XS:

use warnings; use strict; use Data::Dump; use Text::CSV; # also install Text::CSV_XS for speed my %data; my $csv = Text::CSV->new({ binary=>1, auto_diag=>2, sep_char=>"|", allow_whitespace=>1 }); my $hdr = $csv->getline(*DATA); while ( my $row = $csv->getline(*DATA) ) { push @{ $data{ $row->[0] } }, $row->[1]; } $csv->eof or $csv->error_diag; dd \%data; __DATA__ ColA | ColB | 500001| Network1| 500001| Network2| 500002| Network2| 500003| Network1| 500003| Network3|

Replies are listed 'Best First'.
Re^3: Need to get hash of arrays
by chandantul (Scribe) on May 15, 2021 at 18:40 UTC

    Hello Smart Monks, Thanks for your help. I have fixed this by below assignment

    push @{ $hash4{$cellp[$_]} }, $cellr[$_] for (0..$#cellp);

    I have fixed by below and lable as appropriate about within network or no network users

    if (grep { grep { $_ eq "No Network" } @{$hash4{$celln[$o]}} } keys %h +ash4) { worksheet->write($r12, 2, "Non Network"); }

    Thanks for your help.