Mr. aitap I tested your snippet, without modification it would give away
"Modification of a read-only value attempted at" error
nevertheless that snippet of yours is a beautiful code mate
and here i'm using it
thank you
and here the complete script for the author,
it processes 4 files in a loop
files are named file1-4
for ($i = 1; $i < 5; $i++){
$a[$i]{'name'} = "file$i";
open IN, "<file$i" or die $!;
while(<IN>){
if (/(\w)\t(\w)\t([\d\.]+)/){
$a[$i]{"$1$2"} = $3;
$a[$i]{'total'} = sprintf('%.2f', $a[$i]{'total'}+=$3)
+;
}
}
close(IN);
}
foreach $key ('name', grep {$_ ne 'name'} sort keys $a[1]){
print join "\t", $key, map($_->{$key}, @a[1..4]),"\n";
}
and output:
name file1 file2 file3 file4
AB 12.00 01.00 02.00 62.00
CD 13.00 04.00 03.00 43.00
EF 11.00 42.00 15.00 24.00
GH 22.00 34.00 20.00 26.00
total 58.00 81.00 40.00 155.00
files which are used, created from the author's output:
~@deb:~/perl/9# cat file1
A B 12.00
C D 13.00
E F 11.00
G H 22.00
~@deb:~/perl/9# cat file2
1 A B 01.00
2 C D 04.00
3 E F 42.00
4 G H 34.00
~@deb:~/perl/9# cat file3
A B 02.00
C D 03.00
E F 15.00
G H 20.00
~@deb:~/perl/9# cat file4
1 A B 62.00
2 C D 43.00
3 E F 24.00
4 G H 26.00
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.