At 11:33 am -0400 19/6/01, Brandon Barker wrote:
>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);
>    }
>}
>
[...]

Add this line to the beginning of the script:

$/ = '';

That makes Perl ignore the newlines and makes the regexp work on the 
entire file.

The reason it's working in Linux is probably due to the line breaks 
in the file not having been converted into native line-breaks: to 
Linux the file consists of only one line.
-- 
My brain hurts!
SeanC
                      Mediatek Training Institute
            26 Crart Ave., Berea, Durban, South Africa
    phone: +27 (0)31 202 1886              [EMAIL PROTECTED]
       fax: +27 (0)31 202 1767
                   <http://members.nbci.com/s_carte/>

Reply via email to