http://qs321.pair.com?node_id=552313

chanakya has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a working script and looking ways to improve the code . I came across a line which splits the CSV file to get the values. This line is very long becaus around 100 variables are specified for each of the splitted element from CSV file and is hard to maintain. The code is :
use strict; use warnings; my $file = "/tmp/index.csv"; open (FL, "< $file"); while ($line = <FL>){ my ($country, $exchange, $name, $forex, $ric, $isin, $cusip) = +split(/\;/ $line); #similarly 100 vars are declared }
CSV file format:
##CSV file format Country;Exchange;NAME;Forex;RIC;ISIN;CUSIP; AT;XETRA (AT) ;RAIFFEISEN INTERNATIONAL BANK ;EUR;RIBH.VI +;AT0000606306; ;B0704T9; AT;XETRA (AT) ;IMMOEAST IMMOBILIEN ANLAGEN AG;USD;IMEA.VI +;AT0000642806; ;
The first line of the CSV is the header. Using map function I want to dynamically assign the splitted values to the variables given in the header of CSV (Country;Exchange;NAME;Forex;RIC;ISIN;CUSIP;). i.e the final output should look like:
$Country = "AT"; $Exchange ="Xetra (AT)"; $NAME = "RAIFFEISEN INTERNATIONAL BANK "; #etc..
I'd like some suggestions on how to dynamically map the splitted values in the above way.