drock has asked for the wisdom of the Perl Monks concerning the following question:
All,
I need to search a file for a string then set a variable using substr b/c it is at a certain position, then finally replace the string with another string. Thank you,
Here is my test code:
my $gpg=qq(/home/gpghrp/.gnupg); open (GPG, "gpg --fingerprint |") or die "unable to open pipe sys call + (1)... Broken? $!"; open(OLD,"+<$gpg/scripts/gpg_encr.saved") or die $!; open(NEW, "+<$gpg/scripts/gpg_encr.saved.new") or die $! for (;<OLD>;) { if ( /(?)readonly tlx=/ ) { my $ns =substr($_,13,8) print "Now substituting\n"; print NEW s/$ns/"blah"/; } } close (GPG); close (SYS);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: search and replace with a temp file at a certain substr position
by ikegami (Patriarch) on Jul 20, 2005 at 19:34 UTC | |
Re: search and replace with a temp file at a certain substr position
by jdporter (Paladin) on Jul 20, 2005 at 20:21 UTC | |
Re: search and replace with a temp file at a certain substr position
by Zaxo (Archbishop) on Jul 20, 2005 at 19:35 UTC | |
by drock (Beadle) on Jul 20, 2005 at 21:11 UTC |
Back to
Seekers of Perl Wisdom