lloder174 has asked for the wisdom of the Perl Monks concerning the following question:
I have written a program which can load regular expressions from a user designated file containing expressions in a standardized format, but it does not work successfully with all legal expressions. I would like to determine if there is a way to have the following expressions parsed appropriately to achieve the desired result of finding a 'shebang' line and inserting a usage line for the English module, (surrounded by two blank lines!)
Here's a copy of an 'LTL'-separated line which I am loading from a file containing a hash key, a search expression, and a replace expression:
When loaded into my code it yields:" (^\#!/usr/bin/perl[^\n]*\n)LTL(^\#!/usr/bin/perl[^\n]*\n)LTL(^\#!/usr/ +bin/perl[^n]*n)LTL${ "
When I slurp the file to be searched into the $content variable I execute$regExpKey = (^\#!/usr/bin/perl[^\n]*\n) $searchPattern = (^\#!/usr/bin/perl[^\n]*\n) $replacementPattern = ${^MATCH}\x0Ause English \( no_match_vars \);\x0 +A
and it $content becomes the following:$content =~ s{$searchPattern}{${^MATCH}$replacementPattern}gxms;
" ${^MATCH}\x0Ause English \( no_match_vars \);\x0A "
e.g. ${^MATCH} is not interpolated(?) and the newlines, (\x0A), are not inserted, even if I were to use "\n"'s!
Please help me understand whether or not what I am attempting is doable and/or practical and, if so, how do I rectify what I am doing in error?20090605 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to load regular expressions from a file
by CountZero (Bishop) on Jun 02, 2009 at 13:48 UTC | |
|
Re: how to load regular expressions from a file
by ikegami (Patriarch) on Jun 02, 2009 at 14:34 UTC |