SPUG: reg exp generator
Benjamin Turner
bjturner at mac.com
Mon Jul 29 16:17:56 CDT 2002
On Monday, July 29, 2002, at 01:44 PM, Baker, Stephen M wrote:
>
> I have a program needing with the following array:
>
> @LINES = qw( #any line from file here
>
> );
>
> That at the present time I want to do the following:
>
> foreach $line (@LINES){
> $line =~ s/$line/$CONSTANT_MOD_LINE/
> }
>
> The goal is that a user can put a line from an output file into
> the array,
> and my program will take the line and essentially comment out
> any lines in
> all files that contain the user's selected line... however, my
> original idea
> was to do this using regular expressions and since some lines have a or
> multiple period(s) or asteric(s) the reg exp is giving me some
> trouble...
> any ideas on how to change ordinary text, especially periods
> and asterics
> into reg exp friendly characters?
You want your regexp line to look like this:
$line =~ s/\Q$line\E/$CONSTANT_MOD_LINE/;
The \Q...\E will regexp-escape all regexp-special characters
between them. This should be documented in 'perldoc perlre' if
you need further explanation.
Ben
--
Benjamin John Turner | bjturner at bigfoot.com
http://www.usfca.edu/turner/ | bjturner at mac.com
"The happiest of people don't necessarily have the best of
everything; they just make the most of everything that comes
along their way."
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list