![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl array question from going through hash | hankooknara | Shell Programming and Scripting | 2 | 07-29-2007 06:53 PM |
| hash,array and perl | new2ss | Shell Programming and Scripting | 3 | 05-23-2007 08:30 AM |
| md5 hash a string or char array in SCO | jcarter2333 | High Level Programming | 5 | 02-08-2007 12:09 PM |
| Hash within array, within hash, within array... | jsmoriss | Shell Programming and Scripting | 1 | 07-10-2006 06:26 PM |
| getting data list into a hash array | topcat8 | Shell Programming and Scripting | 5 | 03-09-2004 08:02 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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; |
| Forum Sponsor | ||
|
|
| Thread Tools | |
| Display Modes | |
|
|