jvector has asked for the wisdom of the Perl Monks concerning the following question:
What am I doing wrong here? I read a line of text and do a simple match. Because I want to Do It Right, I use /x. And it Doesn't Work. The lines look like this:
000.000.002.249-2-P 09-11-2007 15:27:30 102_Low_Alarm 000.000.002.249-2-P 09-11-2007 16:44:18 102_Low_Alarm 000.000.002.249-2-P 09-11-2007 16:44:18 202_Low_Repeat
and the code is below :
while (<>) { chomp; my ($meter,$dt,$type) = ($_ =~ (\S+) #ser no \s+ (\d\d-\d\d-\d\d\d\d \d\d:\d\d:\d\d) # 12-11-2007 13:51:30 \s+ (\S+) #102_Low_Alarm $/x); .... }
Running under -d, I get this:
DB<15> ($a,$b,$c)= ($line =~ m/(\S+)\s+(\d\d-\d\d-\d\d\d\d \d\d:\d\d +:\d\d)\s+(\S+)$/x ) ; DB<16> x ($a,$b,$c) 0 undef 1 undef 2 undef DB<17> ($a,$b,$c)= ($line =~ m/(\S+)\s+(\d\d-\d\d-\d\d\d\d \d\d:\d\d +:\d\d)\s+(\S+)$/ ) ; DB<18> x ($a,$b,$c) 0 '000.000.002.249-2-P' 1 '09-11-2007 15:27:30' 2 '102_Low_Alarm' DB<19> x $line 0 '000.000.002.249-2-P 09-11-2007 15:27:30 102_Low_Alarm'
I've just checked and it's not an artefact of running in the debugger; I made 2 versions with and without the /x, and they run differently. I'm obviously missing something very ... obvious.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Unexpected behaviour of /x Regexp modifier?
by JavaFan (Canon) on Mar 16, 2009 at 19:32 UTC | |
Re: Unexpected behaviour of /x Regexp modifier?
by repellent (Priest) on Mar 16, 2009 at 19:34 UTC | |
Re: Unexpected behaviour of /x Regexp modifier?
by jvector (Friar) on Mar 16, 2009 at 19:53 UTC | |
by codeacrobat (Chaplain) on Mar 16, 2009 at 20:27 UTC | |
by johngg (Canon) on Mar 17, 2009 at 10:47 UTC | |
by ysth (Canon) on Mar 17, 2009 at 01:59 UTC | |
Re: Unexpected behaviour of /x Regexp modifier?
by Marshall (Canon) on Mar 16, 2009 at 23:03 UTC |