On Mon, Sep 23, 2002 at 05:39:43PM -0400, Erik Price wrote:
> Anyone know of a way to get a regular expression to respect the input 
> record separator ( $/ ), so that "$" represents the end of a line as 
> defined by $/ ?
> 
> Here's my code:
> 
> #!/usr/bin/perl -w
> use strict;
> 
> $/ = '    ';            # my input data is not newline separated,
>                         # rather, it appears to be separated by four 
> spaces
>                         # per record
> my $mileage;
> 
> while (<DATA>) {
>       if (m/(\d+\.\d{1,2})$/) {
>               $mileage += $1;
>       }
> }

One way would be to interpolate the record separator into the regex:

if (m,(\d+\.\d{1,2})\Q$/,) {


However, it might be preferable to remove the record separator with
chomp(), and then just match the end of the string with \z.  That way you
won't have a problem at the end of the file.


Ronald
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to