I am trying to refactor a lot of files to use the English module and I am running into problems that are totally puzzling to me using Perl RegExp's with my interpreter.
My code is intended to find the first line containing my search text and replace that line with whatever was there plus a blank line and an additional line for 'use' of the English module.
Unfortunately the searched for line is becoming the third line and the 'blank line and additional line' are preceding it - a reverse of the desired order, which boggles my mind!!!
Hellllpppp!!!
here's the code in question:
#!/usr/bin/perl -w ###-DDEBUGGING -d -Dslt`
use Env;
use English ( no_match_vars );
local $INPUT_RECORD_SEPARATOR;
my $searchPattern = "(^\#!/usr/bin/perl.*?\n)";
my $insertion = "\nuse English \( no_match_vars \);\n";
#my $content = "#!/usr/bin/python\n";
my $content = "#!/usr/bin/perl\n";
print "content = \n$content \n";
print "insertion = \n$insertion \n";
$content =~ s?${searchPattern}?${1}${insertion}?xmsp;
print " content now = \n$content \n";
exit 0;
20090430 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.