substitution doesn't work on all files ?



Hi All,
 
Now that I have my program working ( much thanks to the group ) I'm totally stumped as to why the substitution only works on some of the .txt files and not all.     I'm attaching two files..  70119.txt and 30700.txt.  The s/ / /; in the program below works for file 70119.txt and not for file 30700.txt..  and I have no idea why... :~)   If anyone can tell me why this is happening, I would really appreciate it! 
 
Thanks again!
 
__BEGIN__
 
#!/usr/bin/perl
 
use strict;
use warnings;
use File::Basename;
use File::Copy;
 
my $pdf_dir = "j:/flash_host/ecomm/descriptions/product/MSDS";
# read file/directory names in that directory into @pdfs
opendir PDFDIR, $pdf_dir
   or die "Can't opendir $pdf_dir: $!\n";
my @pdfs = readdir(PDFDIR);
closedir PDFDIR;
 
my $text_dir = "c:/brian/descriptions/product/small";
# my $text_dir = "j:/flash_host/ecomm/descriptions/product/small";
opendir TEXTDIR, $text_dir
   or die "Can't opendir $text_dir: $!";
my @txts = map { "$text_dir/$_" } grep { !/^\./ } readdir TEXTDIR;
closedir TEXTDIR;
 
my %PDFDIR_LIST;
$PDFDIR_LIST{$_}=1 for @pdfs;
 
foreach my $text_file (@txts) {
 my ($basename, $suffix) = fileparse($text_file,'.txt');
 my $link = "descriptions/product/MSDS/$basename.pdf";
 
 if( $PDFDIR_LIST{"$basename.pdf"} ) {
  my $out_file = "$text_file.new";
  open INPUT, "< $text_file"
     or die "can't open $text_file: $!";
  open OUTPUT, "> $out_file"
     or die "can't open $out_file: $!";
  
  while (<INPUT>) {
   s% http://.* % $link %g;
   print OUTPUT;
  }
  close INPUT; close OUTPUT;
  move( $text_file, "$text_file.bak" );
  move( $out_file, $text_file );
 }
}
 
__END__
 
Brian Volk
HP Products
317.298.9950 x1245
bvolk@xxxxxxxxxxxxxx
 
All Surface/All Purpose Cleaner. 12/32 oz./cs. includes 3 trigger sprayers http://www.spartanchemical.com/sfa/MSDSRep.nsf/18ce12380374a5da8525665f00619f51/d111b733947e4d5485256ee0006ba2c8!OpenDocument
Non-acid disinfectant bathroom cleaner. Ready-to-use. Kills HBV and HCV on inanimate surfaces. EPA Reg. #5741-18  ~                                                                                                                                            http://www.spartanchemical.com/sfa/MSDSRep.nsf/99b229d7d7868537852567e0006d7a64/671a7d07c725353885256e9f0063c4cc!OpenDocument                                                                                                                                                               


Relevant Pages