Hello Monks,

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.


This signature no verb

In reply to Unexpected behaviour of /x Regexp modifier? by jvector

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.