You're closing the <INNEWSFILE> after the first line is written to the
<OUTTEXTFILE>. I forgot how to "slurp" a file to a scalar, but I would
use the code below:
#!/usr/bin/perl -w
{
foreach $inFile (@ARGV) {
open (INNEWSFILE, $inFile);
@newsFile = <INNEWSFILE>; # read entire file to an array
$newsFile = join '', @newsFile; # create a scalar from the array
close (INNEWSFILE); # don't need the file open anymore
$newsFile =~ s/<B>//g; # do your substitution
open (OUTTEXTFILE,">".$inFile.".txt"); # open output file
print OUTTEXTFILE $newsFile; # and write to it.
close (OUTTEXTFILE); # Don't forgot to close it
}
}
This reads the entire file to an array, what you had just read the first
line, and go to the next command, whcih was the substitution. This code
will then create a scalar with all the lines (line breaks kept intact)
which can be used in the substitution function, and then written back to
your output file.
This isn't the only way or the best way to do this, depending on the size
of these files, but it should get the job done.
Good luck,
--Steve
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 19, 2001 11:30 AM
Subject: macperl-anyperl Digest 19 Jun 2001 15:30:19 -0000 Issue 8
I'm having trouble writing a script that will remove the regular
expression "<B>" in a text file in macperl. At first I thought I was
making a programming mistake but I tried the same script in Linux and it
worked as expected; in macperl the <B> will be removed but every line
after the first will be deleted in the output file. I've included the
code as well as the droplet and a sample input file "funerals" in this
email.
#!/usr/bin/perl -w
{
foreach $inFile (@ARGV) {
open (INNEWSFILE, $inFile);
open (OUTTEXTFILE,">".$inFile.".txt");
$newsFile = <INNEWSFILE>;
$newsFile =~ s/<B>//g;
print OUTTEXTFILE $newsFile;
close (INNEWSFILE);
}
}