Oh. One more thing. Your regex should have the . escaped. Currently it is matching on either a number or *any character* between the a and z. Although this works, it may bite you if you have a line like this...
30000034364717283459322a15f32zM 042001H which you don't want to include in the results. Here is how it should look /a([\d\.]+)z/ John -----Original Message----- From: John Edwards [mailto:[EMAIL PROTECTED]] Sent: 25 January 2002 09:16 To: 'Stuart Clark'; Perl List Subject: RE: simple perl question This line $total += /a([\d.]+)z/; is adding the number of successful matches (1 for each iteration in this case) of the regex to $total. There are three lines, three matches. You need to store the result of the regex as a list value, not scalar. while (<IN>) { ($match) = /a([\d.]+)z/; $total += $match; } HTH John -----Original Message----- From: Stuart Clark [mailto:[EMAIL PROTECTED]] Sent: 25 January 2002 02:58 To: Perl List Subject: simple perl question 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 --------------------------Confidentiality--------------------------. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------Confidentiality--------------------------. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]