Phil
2014-10-06 15:11:02 UTC
Hello There,
I have a text file that is built up as follows:
Naam;ISIN;Symbol;Market;Trading Currency
IDI;FR0000051393;IDIP;Euronext Paris;EUR
BETER BED;NL0000339703;BBED;Euronext Amsterdam;EUR
...
GENTICEL;FR0011790542;GTCL;Euronext Paris,Brussels;EUR
With the following code, I can read this text file into hashes:
--------------------------
use strict;
use warnings;
my %data;
my @names;
my $myFile = "myfile.csv";
open(FH, '<', $myFile) or error("Cannot open file ($!)");
while (<FH>){
chomp;
my @list=split(';');
for (my $i=0; $i<=$#list; $i++){
if ($.==1){
$names[$i]=$list[$i];
}
else {
push @{$data{$names[$i]}}, $list[$i];
}
}
}
close FH;
--------------------------
First Question:
I wish to create an additional column/list which will be a combination
of the "Symbol" and "Market".
The new column needs to contain the Symbol plus the one of the following cases:
- Euronext Amsterdam ==> append ".PA"
- Euronext Brussels ==> append ".BR"
- Euronext Paris ==> append ".PA"
Second Question:
How can I print all of the columns to a tab-delimited text file? The
following are the headers of the (new) text file:
Naam ISIN Symbol Ticker Market Trading Currency
Thanks for your tips/help.
Best regards
Phil
I have a text file that is built up as follows:
Naam;ISIN;Symbol;Market;Trading Currency
IDI;FR0000051393;IDIP;Euronext Paris;EUR
BETER BED;NL0000339703;BBED;Euronext Amsterdam;EUR
...
GENTICEL;FR0011790542;GTCL;Euronext Paris,Brussels;EUR
With the following code, I can read this text file into hashes:
--------------------------
use strict;
use warnings;
my %data;
my @names;
my $myFile = "myfile.csv";
open(FH, '<', $myFile) or error("Cannot open file ($!)");
while (<FH>){
chomp;
my @list=split(';');
for (my $i=0; $i<=$#list; $i++){
if ($.==1){
$names[$i]=$list[$i];
}
else {
push @{$data{$names[$i]}}, $list[$i];
}
}
}
close FH;
--------------------------
First Question:
I wish to create an additional column/list which will be a combination
of the "Symbol" and "Market".
The new column needs to contain the Symbol plus the one of the following cases:
- Euronext Amsterdam ==> append ".PA"
- Euronext Brussels ==> append ".BR"
- Euronext Paris ==> append ".PA"
Second Question:
How can I print all of the columns to a tab-delimited text file? The
following are the headers of the (new) text file:
Naam ISIN Symbol Ticker Market Trading Currency
Thanks for your tips/help.
Best regards
Phil
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/