P
Paul Lalli
I am attempting to use File::Stream to set $/ to a regular expression
that will match integers or floating point numbers. (This is a
learning exercise only - I am well aware of the various Regexp::Common
abilities to more robustly match numbers). For reasons I have not been
able to diagnose, the stream is not terminating on any integer value -
only on floating points.
Below is my short-but-complete script. I am using the DATA filehandle
below, but have seen the same results when used with an actual
filehandle.
#!/usr/bin/perl
use strict;
use warnings;
use File::Stream;
my $stream = File::Stream->new(*DATA);
local $/ = qr/\d+(?:\.\d+)?/;
#local $/ = qr/\d+\.?\d*/;
while (<$stream>){
print "Line: '$_'\n";
}
__DATA__
foo 35.3 bar 35 baz
Output as is:
Line: 'foo 35.3'
Line: ' bar 35 baz
'
If I switch the commented line, so that the regular expression is the
less-correct /\d+\.\d*/, these are the results:
Line: 'foo 35.3'
Line: ' bar 35'
Line: ' baz
'
Can someone help me to understand why the first version does not also
terminate a readline on the 35?
Much obliged,
Paul Lalli
that will match integers or floating point numbers. (This is a
learning exercise only - I am well aware of the various Regexp::Common
abilities to more robustly match numbers). For reasons I have not been
able to diagnose, the stream is not terminating on any integer value -
only on floating points.
Below is my short-but-complete script. I am using the DATA filehandle
below, but have seen the same results when used with an actual
filehandle.
#!/usr/bin/perl
use strict;
use warnings;
use File::Stream;
my $stream = File::Stream->new(*DATA);
local $/ = qr/\d+(?:\.\d+)?/;
#local $/ = qr/\d+\.?\d*/;
while (<$stream>){
print "Line: '$_'\n";
}
__DATA__
foo 35.3 bar 35 baz
Output as is:
Line: 'foo 35.3'
Line: ' bar 35 baz
'
If I switch the commented line, so that the regular expression is the
less-correct /\d+\.\d*/, these are the results:
Line: 'foo 35.3'
Line: ' bar 35'
Line: ' baz
'
Can someone help me to understand why the first version does not also
terminate a readline on the 35?
Much obliged,
Paul Lalli