hi ,
i am reading text from all the files in a directory one by one and then doing something with it . After manioulation i am writing the new data to to a text file with same name and extension .txt. But, i get empty files as a result of it . i did some trial and error to find where the problem was and it comes up that nothing is being read from the text file and so there is nothing to write back into the new file . i cant figure out why this is happening . can u help me find my fault?? here's the code
#!c:\perl\perl.exe
# open directory and get all filenames in one array
my $path = "c:/perl/dvd_files/";
opendir(LOCAT, $path) or die "Couldn't open folder, $!\n";
my @folder = grep !/^\.\.?$/, readdir(LOCAT);
closedir (LOCAT);
# foreach file open it and strip pattern and rewrite a text file
foreach my $file (@folder)
{
my $full_path = $path.$file;
#print "$full_path\n";
open SWORD, "< $full_path" or die "file could not be opened:$!";
print "here\n";
$full_path =~ s/sub/txt/gi;
$full_path =~ s/srt/txt/gi;
$full_path =~ s/txt/txt/gi;
open WRITE, "> $full_path" or die "file could not be written:$!";
while (<SWORD>){
print "$_\n";
$_=~ s/[\{0-9\}\{0-9\}]//g;
print "here";
print WRITE $_;
}
close (SWORD);
close (WRITE);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.