$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.
|