substitution doesn't work on all files ?
- From: BVolk@xxxxxxxxxxxxxx (Brian Volk)
- Date: Fri, 5 Aug 2005 16:43:07 -0500
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;
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;
# 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 $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;
$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 );
}
}
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__
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
- Follow-Ups:
- Re: substitution doesn't work on all files ?
- From: Jeff 'japhy' Pinyan
- Re: substitution doesn't work on all files ?
- Prev by Date: RE: Net::DNS - Specify a Name Server
- Next by Date: Re: substitution doesn't work on all files ?
- Previous by thread: Net::DNS - Specify a Name Server
- Next by thread: Re: substitution doesn't work on all files ?
- Index(es):
Relevant Pages
|