in reply to Can't match my regex
Second Update: Aaargh!
Wrong, wrong, wrong (except the genuflection)!
On the other hand (but with a bow and ++ to Marshall's remarks regarding \r, \n and the "$end of string anchor"), I do see the same issue Update: stricken text replaced read OP incorrectly</replace> see an issue, both with perl v 5.8.7 under Linux (Ubuntu) and with perl v 5.8.8 (Build 819) under W2K.
The issue is with the parenthesized ($version). See context.
Simple minded testing
#!/usr/bin/perl use strict; use warnings; #793602 my $line = "Version: 0\r\n"; my $line1 = "Version: 0\r\n"; my $line2 = "Version: 0\r\n"; my $line3 = "Version: 0\r\n"; $line =~ s/\n|\r//g; print "Line: |$line| ... \n"; $line1 =~ /^Version:\s(\d)$/; print "Line1: -|$line1|- ... \n"; $line2 =~ /^Version:(\s\d+)$/; print "Line2 with \\s inside capture: --|$line2|-- ... \n"; my ($version) = $line3 =~ /^Version:\s(\d)$/; print "Line3 (paren'ed \$version): ---|$version|--- ... \n"; =head OUTPUT Line: |Version: 0| ... Line1: -|Version: 0 |- ... Line2 with \s inside capture: --|Version: 0 |-- ... Use of uninitialized value in concatenation (.) or string at 793602.pl + line 22. Line3 (paren'ed $version): ---||--- ... =cut
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't match my regex
by Saladino (Beadle) on Sep 05, 2009 at 09:49 UTC |