thanks zaxo , i agree with you that i overdid somethings. your code seems to work much better for me . i have another query though . this code that i am posting now is taken from a site for stripping HTML . It does the same thing that my other code was doing , generated empty txt files and gives me "Use of uninitialised variable " error for $plain_text. can any body tell me why??
#!c:/perl/perl.exe
use strict;
use warnings;
use CGI ':standard';
use HTML::Parser;
my $plain_text ;
my $p = HTML::Parser->new(text_h => [\&text_rtn, 'text']);
my $path = "c:/perl/htmlfiles";
opendir(LOCAT, $path) or die "Couldn't open folder, $!\n";
my @folder = grep !/^\.\.?$/, readdir(LOCAT);
closedir (LOCAT);
# Do a loop for each file in the folder. This gets the filename also.
foreach my $file (@folder)
{
my $full_path = $path.$file;
print "Reading '$full_path'\n";
$p->parse_file($full_path);
$full_path =~ s/html/txt/gi;
$full_path =~ s/htm/txt/gi;
print "Writing '$full_path'\n";
open(WRITE,">$full_path") or die("Cannot create file!");
print WRITE $plain_text;
close(WRITE);
}
sub text_rtn {
foreach (@_) {
$plain_text .= "$_\n";
}
}
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.