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);
In reply to Writing to a file: problem by Tricky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |