Read csv into Hash array?

Hi all experts,

May I know how to read a csv file and read the content in a hash in PERL?
Currently, I hard-coded and defined it in my code. I wanna know how to make up the %mymap hash thru reading the cfg.txt

====
csv file(cfg.txt):
888,444
999,333

#!/usr/bin/perl

my $file='p.csv';
my %mymap;
$mymap{888} = 444;
$mymap{999} = 333;

open(my $data, '<',$file) or die "Cannot open 'file'\n";
while (my $line=<$data>) {
my @column = split ",", $line;
if ($line =~ /Doc/) {
if (exists $mymap{$column[2]}) {
$column[3]=$mymap{$column[2]};}
foreach my $i (0..$#column) {
if ($i > 0) {
print ",",$column[$i];}
else {
print $column[$i];}
}}
else {
print $line}
}
exit;

Hi.

Here is one way:

#!/usr/bin/perl

# @(#) p2       Demonstrate building hash (almost) directly from a file.

use warnings;
use strict;

my ($debug);
$debug = 0;
$debug = 1;

chomp( my (%hash) = map { split "," } my (@a) = <> );

foreach my $k ( keys %hash ) {
  print " key = $k, value = $hash{$k}\n";
}

exit(0);

Producing (with your data on file "data1"):

% ./p2 data1
 key = 888, value = 444
 key = 999, value = 333

See perl man pages or perldoc for details ... cheers, drl