Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: add after $1

by hipowls (Curate)
on Mar 20, 2008 at 22:25 UTC ( [id://675331]=note: print w/replies, xml ) Need Help??


in reply to add after $1

You are reading in single lines and then testing if that line has an 'if' and a 'fi' in it. Since the if statement you are looking for spans multiple lines you won't find it that way.

Your choices are to read in the entire script to a single string or to process the file a line at a time remembering the state of your search. The first is easiest and, assuming your script is not several hundred Megabytes in size, practical.

use strict; use warnings; my $here=<<HERE; if /usr/bin/pgrep -x -u 0 -P 1 ltps& >/dev/null 2>&1; +then echo "$0: ltps is already running" exit 0 fi HERE my $file = do { local $/; <DATA> }; $file =~ s/^(if.*?rctladm\.conf.*?fi$)/$1\n$here/ms; print $file; __DATA__ # Run rctladm to configure system resource controls based on the setti +ngs # previously saved by rctladm. See rctladm(1m) for instructions on ho +w to # modify resource control settings. # if [ -f /etc/rctladm.conf ] && [ -x /usr/sbin/rctladm ]; then /usr/sbin/rctladm -u fi
produces
# Run rctladm to configure system resource controls based on the setti +ngs # previously saved by rctladm. See rctladm(1m) for instructions on ho +w to # modify resource control settings. # if [ -f /etc/rctladm.conf ] && [ -x /usr/sbin/rctladm ]; then /usr/sbin/rctladm -u fi if /usr/bin/pgrep -x -u 0 -P 1 ltps& >/dev/null 2>&1; +then echo "Perl-1.pl: ltps is already running" exit 0 fi
You may want to look at the indenting of your replacement text.

Replies are listed 'Best First'.
Re^2: add after $1
by wcj75019 (Acolyte) on Mar 20, 2008 at 22:45 UTC
    SWEEEET! Thank You hipowls!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://675331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found