B
beartiger
Can anyone tell me why the folling script works on one file but not on
glob(*.html)?
The script is designed to take the following line:
<filestatus owner="jeh" status="1"/>
Strip out the "status" value and then translate it into a string that
appears to the user at the bottom of the file.
When I run the script in glob mode in a dir of .html files, "$stat" is
filled with the entire contents of each file [!]. When I run it on a
single file, "$stat" is correctly filled only with the status value and
the script runs as intended and correctly updates the file.
======================CODE STARTS============================
use strict;
use warnings;
my @files;
if ($ARGV[0])
{
@files= $ARGV[0];
} else
{
@files=glob('*.html');
}
my $stat;
foreach my $file (@files)
{
# first get the file's status
#LOAD
open (HTM, "$file") || die("Error
Reading File: $file $!");
while(<HTM>)
{
if(m/filestatus/)
{
s/.*<filestatus.*?status=\"(\d)\".*?>.*/$1/g;
$stat=$_;
$_="";
}
}
close (HTM) || die("Error
Closing File: $file $!");
# then, based on the code, update the bottom line
open (IN, "$file") || die("Error
Reading File: $file $!");
undef $/; my $remthis= <IN>;
close (IN) || die("Error
Closing File: $file $!");
#CHANGE
if ($stat==0) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Placeholder<\/font><\/html>/g;}
if ($stat==1) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>First draft<\/font><\/html>/g;}
if ($stat==2) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Peer Reviewed<\/font><\/html>/g;}
if ($stat==3) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>SME Reviewed<\/font><\/html>/g;}
if ($stat==4) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Final draft<\/font><\/html>/g;}
#WRITE
open (OUT, ">$file") || die("Error
Writing File: $file $!");
print OUT $remthis;
close (OUT) || die("Error
Closing File: $file $!");
}
========================CODE ENDS===========================
Many thanks in advance,
John
glob(*.html)?
The script is designed to take the following line:
<filestatus owner="jeh" status="1"/>
Strip out the "status" value and then translate it into a string that
appears to the user at the bottom of the file.
When I run the script in glob mode in a dir of .html files, "$stat" is
filled with the entire contents of each file [!]. When I run it on a
single file, "$stat" is correctly filled only with the status value and
the script runs as intended and correctly updates the file.
======================CODE STARTS============================
use strict;
use warnings;
my @files;
if ($ARGV[0])
{
@files= $ARGV[0];
} else
{
@files=glob('*.html');
}
my $stat;
foreach my $file (@files)
{
# first get the file's status
#LOAD
open (HTM, "$file") || die("Error
Reading File: $file $!");
while(<HTM>)
{
if(m/filestatus/)
{
s/.*<filestatus.*?status=\"(\d)\".*?>.*/$1/g;
$stat=$_;
$_="";
}
}
close (HTM) || die("Error
Closing File: $file $!");
# then, based on the code, update the bottom line
open (IN, "$file") || die("Error
Reading File: $file $!");
undef $/; my $remthis= <IN>;
close (IN) || die("Error
Closing File: $file $!");
#CHANGE
if ($stat==0) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Placeholder<\/font><\/html>/g;}
if ($stat==1) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>First draft<\/font><\/html>/g;}
if ($stat==2) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Peer Reviewed<\/font><\/html>/g;}
if ($stat==3) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>SME Reviewed<\/font><\/html>/g;}
if ($stat==4) {$remthis=~ s/.*?<.html>/<font
color=#CCCCCC>Final draft<\/font><\/html>/g;}
#WRITE
open (OUT, ">$file") || die("Error
Writing File: $file $!");
print OUT $remthis;
close (OUT) || die("Error
Closing File: $file $!");
}
========================CODE ENDS===========================
Many thanks in advance,
John