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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.