![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl array question from going through hash | hankooknara | Shell Programming and Scripting | 2 | 07-29-2007 09:53 PM |
| hash,array and perl | new2ss | Shell Programming and Scripting | 3 | 05-23-2007 11:30 AM |
| md5 hash a string or char array in SCO | jcarter2333 | High Level Programming | 5 | 02-08-2007 04:09 PM |
| Hash within array, within hash, within array... | jsmoriss | Shell Programming and Scripting | 1 | 07-10-2006 09:26 PM |
| getting data list into a hash array | topcat8 | Shell Programming and Scripting | 5 | 03-09-2004 12:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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; |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|