Let's take a look at your regex:

$def =~ s/ (^\.\w+\s) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := some whitespace (.+) ## $4 := Some anything ( ## $5 ^ ## The start of string/line select ## The word 'select' \. ## A literal '.' . ## Any single character $ ## The end of the line/string ) /$2$5/x; ## put back just first word and the 'select' etc

Look at $5. ^ only matches the start of the string (which you already did in $1), unless you use the /m modifier.

Same goes for $.

Now look at the $4. '.' will not match a newline character unless you use /s. So, you will never reach the 'select' keyword, becuase your regex won't search beyond the end of the first embedded newline.

Continuing with $5. With \..$ I think you are trying to match the '..' at the end of the string.

First, that would need to be \.\.$

But also, you haven't specified anything to bridge the gap between 'select' and '..', so it won't even get there.

Maybe this will get you started, but you will have to read perlre and perlreref and try to undewrstand what is going on. If you come back asking for the next part to be solved for you without having made some progress in your own attempts, it likely will fall on deaf ears.

#! perl use warnings; use strict; my $def = <<'EOD'; .define get_user_info select user_location,user_name, user_company, &fax_header || +';style=' || letterhead, fax_printer, nvl(fax_yn,'N') into user_location, user_name, user_company, fax_header, fa +x_printer, fax_yn from security_header where user_id = lower(substr(user,5,10)) .. EOD $def =~ s/ ( \A \. \w+ \s ) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := Some whitespace (.+?) ## $4 := Some anything ( ## $5 \s+ ## Some whitespace select ## The word 'select' [^.]+ ## Lots of anything except a '.' \. \. \Z ## Two '.'s and the end of line ) /$2$5/smx ## . matches \n; ^ & $ match lines with the string or die 'Failed to match'; print $def;

You see those lines at the top of the code above. They are for your benefit, not the compiler's.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Converting Oracle report language code into perl by BrowserUk
in thread Converting Oracle report language code into perl by denzil_cactus

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.