Re: [PBML] alteration of text strings within a file...??
- I think the best way to do this would be to read in the file a line at a time
and match it with a regex, then substitue accordingly. Something like my
example at the bottom will work.
open IN, "<file.html";
open OUT, ">out.html";
# Will ready file.html a line at a time and assign the line to the var $_
# Replace with your matches/substitutions.
# This will remove all HTML tags from the $_ variable, ie, current line.
#prints $_ to out.html
On Wednesday 25 April 2001 18:17, you wrote:
> Hi All,
> I am trying determine the best course of action and need some
> I need to alter 6 different html files and in each case the edits are
> very light (appending a URL string or changing a port# etc..). My
> problem is that I must use perl and I must do this from within the
> body of a larger script..in sed I would use regular expressions and do
> a find replace (not that I am really any good at sed but it seems
> straight forward enough..from the command line)
> I have been led to believe this type of alteration is easy in perl if
> done from the command line but I do not have that ability give my
> program constraints..also, I know if I open a file to read/write, any
> attempt to write a string will blow away the file contents..
> In an earlier situation I needed to insert a block of text and this
> was pretty easy (example below) but I am uncertain how to aproach
> single word or number changes in multiple files..
> Example from other situation-
> #!/usr/bin/perl -w
> open(SOURCE, "apachectl") || die "opening apachectl: $!";
> open(DEST, ">apache_new") || die "$!";
> print DEST @data[0..2];
> print DEST "new text strings go here
> and on the next line and so on and so on...\n";
> print DEST @data[3..6];
> Should I attempt to search and replace within the contents of an
> array..is this possible or is there an altogether better way to do
> what I am trying to do..
> Any comments greatly appreciated..
> Thanks, Mike
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/