On Fri, Jan 25, 2002 at 01:58:00PM +1100, Stuart wrote: > Hi > Please help if you can. > Thanks again > Stuart Clark > > > How do I add all the number between the "a" and the "z" > My output file only gives me the instances of the matching pattern and > not the total > > # start of file test > 30000034364717283459322a15.32zM 042001H > 30000045434551648534245a243.56zM 040532H > 30000053232540927543293a2.45zM 040332H > # end of file test > > open (IN,"test") || die "Could not open the test file\n"; > open (OUT,">total") || die "Error could not create the output > file\n"; > > while (<IN>) { > > $total += /a([\d.]+)z/; > } > > print OUT $total; > > close(IN) || die "Error cannot close test file\n"; > close(OUT) || die "Error cannot close output file\n"; > > # output file must look like this > 261.33 > > # At the moment it gives me this > 3 ---end quoted text---
> $total += /a([\d.]+)z/; this will match the number of matches in the regular expression, not the values matched. Try: /a+([\d.]+)z and $total=$1; instead. however please note that this regex [\d.] will also match IP addresses since multiple '.' are allowed, it's probably not important in this instance. -- Frank Booth - Consultant Parasol Solutions Limited. (www.parasolsolutions.com) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]