Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: add after $1

by hipowls (Curate)
on Mar 20, 2008 at 22:25 UTC ( #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.


Comment on Re: add after $1
Select or Download Code
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
Node Status?
node history
Node Type: note [id://675331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-07-11 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (220 votes), past polls