- 论坛徽章:
- 0
|
#!D:\strawberry\perl\bin\perl5.12.3 -w
use strict;
use warnings;
my $filename = "d:/cc/cc.txt";
my %h;
open FILE,$filename ||die '$!';
while(my $LINE=<FILE>)
{
my @LINE=split /\|/,$LINE;
while(<@LINE>)
{
#print $_,"\n";
if($_=~/(\w+)(\(\d+\))=([a-z]+)(-?\d+.?\d+)/)
{
if(exists $h{"$1"})
{
$h{"$1"}+=$4;
}else{
$h{"$1"}=$4;
}
}elsif ($_=~/(\w+)(\(\d+\))=([0-9]+)/)
{
if(exists $h{"$1"})
{
$h{"$1"}+=$3;
}else{
$h{"$1"}=$3;
}
}elsif ($_=~/(\w+)(\(\d+\))=([a-z]+)([0-9]+)/)
{
if(exists $h{"$1"})
{
$h{"$1"}+=$4;
}else{
$h{"$1"}=$4;
}
}elsif ($_=~/(\w+)(\(\d+\))=([a-z]+)/)
{
if(exists $h{"$1"})
{
$h{"$1"}+="";
}else{
$h{"$1"}="";
}
}
}
}
close FILE;
while((my $k,my $v) = each %h)
{
print "$k=>$v\n";
}
-----------------------
结果:
D:\PERL练习程序>cc.pl
F4=>
F3=>14
F2=>-23
F1=>12.34 |
|