[Canberra-pm] SEC: UNCLASSIFIED:-A LITTLE HELP...
Jepri
jepri at webone.com.au
Wed Oct 2 07:53:13 CDT 2002
On 2002.10.02 16:04 caroline.scerri at defence.gov.au wrote:
> Hello,
>
> the following is a script which goes through two directory levels of
> the current working directory, upon finding a htm or
> html extension on a file alters the line which calls
> for the cascading style sheet specified at the command line and create
> a new file which has the new
> cascading style sheet reference, also specified at the command line.
> The result (was hoping) should be an exact copy of the htm or html
> file with the altered <LINK> reference, instead i am getting a mirror
> image
> directory
> and file structure in the temporary directory, all files are of zero
> length.
> Can someone please shed some light, the way i am attempting to
> redirect STDOUT ie `open (OUT_FILE, ">>$tmp_html_file")` ,
Redirecting STDOUT is not a trivial operation. It is usually easier to
print into the filehandle instead, like this:
print OUT_FILE "${1}${new_css}${3}";
Note that there is no comma between the file handle and what you want
to print.
If you don't specify a filehandle, it defaults to STDOUT. Perl was
seeing print STDOUT "${1}${new_css}${3}";
However the dot-stars in your regular expression could be a problem.
The first dot-star will swallow everything else on the line, and the
match will fail. You should consider using \s* to catch spaces, and
\S* to catch non-spaces. A good post about the .* can be found at:
http://www.perlmonks.org/index.pl?node_id=24640
> open (OUT_FILE, ">>$tmp_html_file") or print "Couldn't create
> $tmp_html_fil
> e, Skipping: $!\n";
> while (<FILE>)
> {
> if ( /(^\<LINK .*=\".*css\/)($old_css)(\".*\>)/ )
> {
> print "${1}${new_css}${3}";
> }
> else
> {
> print "$_";
> }
> }
> close OUT_FILE;
> close FILE;
More information about the Canberra-pm
mailing list