I have a problem about perfect matching.I want to get the sum of positive and negative integers from a file .Also I want to get dates have same values in the file.
My File:
Hello -12, 3.4 and 32. Where did you
go on 01/01/2013 ? On 01/01/2013, we
went home. -4 plus 5 makes 1.
03/02/2013
Solution:
-16 //the sum of negative integers.
38 //the sum of positive integers.
2 //count of dates have same values.
My code:
$sum=0;
$sum1=0;
while ($_=<>) {
for each($_=~ /_d+g){
$sum+=$_;
}
for each($_=~ /_d+(.| )/g){
$sum1+=$_;
}
foreach($_=~ / d{2}(/d{2}({/d{4})?)?/ {
$count++;
}
}
print "$sum
";
print "$sum1
";
print "$count
";
}
my code is wrong.Please help.I could not print above the results.
See Question&Answers more detail:os