my $data;
my $years = qr{^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)};
my %map = ( 2, 2001, 3, 2002, 4, 2003, 5, 2004 );
while( <DATA> ){
/$years/ or next;
$data->{country}{$1} = [ $2, $3, $4, $5 ];
$data->{years}{$map{$_}} += ${$_} for 2..5;
}
__DATA__
COUNTY 2001 2002 2003 2004
------ ------ ------ ------ ------
26005 432 505 547 555
26021 910 984 1026 1077
26023 225 282 272 299
#If print Dumper($data);
$VAR1 = {
'country' => {
'26149' => [
'355',
'415',
'346',
'367'
],
.....
'years' => {
'2004' => '5734',
'2002' => '5327',
'2001' => '4663',
'2003' => '5503'
}
};
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.