I'm in the process of doing a major overhaul (new features, etc.) on a perl app here and am running into a confusing RegEx issue. In the old, working code I have this RegEx:

m/HOSTNAME:\s*(\d{4}-)?$dev_ref->{hostname}\s+GRBR:\s*$dev_ref->{grbr}/i

However, in the new code this fails.

For debugging purposes I tried the following:

my $pattern = qr{HOSTNAME:\s*(?:\d{4}-)?$dev_ref->{hostname}\s+GRB +R:\s*$dev_ref->{grbr}}i; print "DEBUG: \$pattern='$pattern'\n" if $DEBUG; my $hostname = $buffer =~ m/$pattern/i ? 1 : 0 ;

And here is debug output from the new script (where $buffer is what is in between the ////// dividers):
B  U  F  F  E  R:
///////////////////////////////////////////////////////////////////////////////
 9600/ARQ

                Some Company

---> Unauthorized use of this router is prohibited <---

*******************************************************
* Hostname: 2383-rwan-1                GRBR: 2383    *
* Model: Cisco 1234                                  *
* Location: Ansalon , DL                    *
*******************************************************

---> Unauthorized Access is strictly prohibited <---



User Access Verification

Username:
///////////////////////////////////////////////////////////////////////////////
DEBUG: $pattern='(?i-xsm:HOSTNAME:\s*(?:\d{4}-)?2383-RWAN-1\s+GRBR:\s*2383)'
From tests in the code I know that $hostname is being set to 0. Any ideas why the match always fails in the new code? Note that I tried the exact same RegEx and test from the old script and it still fails. I also tried e.g. matching against '9600' and 'Username' and those also failed. Help!! :-/

UPDATED: Argh!!! I copied old code over to the new app but missed renaming one of the variables. SIGH.... Thanks for the comments and sorry I wasted your time.

-- Argel


In reply to RegEx Confusion by Argel

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.