Tricky has asked for the wisdom of the Perl Monks concerning the following question:
When I run the following script, the code runs but an unitialised print value is declared. I run it again and the entire file I'm writing to is erased! What am I missing?
#!/usr/bin/perl # addwordspacing3.plx =head1 DESCRIPTION Program will read in an html file, append word spacing attribute to th +e in-line style and print in DOS window. =cut use warnings; use diagnostics; use strict; # Open HTML test file - forward slashes do not need to be escaped. open INFILE, "E:/Documents and Settings/Richard Lamb/My Documents/HTML +/dummy.html" or die "$!: Can't open this file.\n"; while (<INFILE>) { s/(<h[1-6]\s+style=.*)">/$1; word-spacing: 50px">/ig; s/(<li\sstyle=.*)">/$1; word-spacing: 20px">/ig; s/(<p style=.*)">/$1; word-spacing: 20px">/ig; print; } close (INFILE); open (OUTFILE, ">E:/Documents and Settings/Richard Lamb/My Documents/H +TML/dummy.html") or die("$!: Can't write to the HTML file.\n"); print (OUTFILE); close (OUTFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing to a file: problem
by tcf22 (Priest) on Sep 04, 2003 at 14:30 UTC | |
|
Re: Writing to a file: problem
by broquaint (Abbot) on Sep 04, 2003 at 14:32 UTC | |
|
Re: Writing to a file: problem
by gjb (Vicar) on Sep 04, 2003 at 14:28 UTC | |
|
Re: Writing to a file: problem
by Abigail-II (Bishop) on Sep 04, 2003 at 14:33 UTC | |
|
Re: Writing to a file: problem
by zby (Vicar) on Sep 04, 2003 at 16:03 UTC |