I need to understand this before i start manipulating HTML files
Here is what i have come up with so far
use strict;
my $chars = 0;
my $words = 0;
my $line = 0;
my $lines = 0;
open(MYINPUTFILE,"database.txt") ¦¦ die("Could not open file!");
while (my $line = <MYINPUTFILE>) {
chomp $line;
$line =~ s/[;:,.!?-]/ /gis;
foreach $w (split(/ /, $line)) {
if ($w eq 'the') {
print "$.\n";
$and++;
}
}
}
print "\n'the' occurs " . $and . " times\n";
$line = $words++ {
$chars += length;
}
close(INFILE);
print "Found $lines lines, $words words and $chars characters.\n";
I would like people to reply with any further ideas?
Then i can plan on manipulating text in a HTML file..
[edited by: phranque at 10:36 am (utc) on Dec. 11, 2008]
[edit reason] disabled smileys ;) [/edit]
go to search.cpan.org and enter the names of the modules in the search box.
there is documentation and sample code for each included.
you should always check cpan.org to see if there is an existing tool you can use or extend or at least get some ideas before developing your own.
when you get to manipulating html, you can use one of the modules that parses html such as HTML::TagParser
having said all that, i don't want to discourage you from doing something simply as a learning experience and we can continue with your posted code.
it's just that many things have already been done in several flavors of perl, so you can do your learning with more power.
=8)
Maybe i need to look more into the structure of data in perl, or more on regular expressions. I dont know?
Can you help me? Maybe an example.
As i dont want to cheat my way to glory!
while ($line = <IN>)
{
$count+=length($line);
}
print "Characters: $count\n";
This works, but I trying to do it by using regular expressions or pattern matching whatever the term is. I try and find a way soon I hope
[edited by: phranque at 12:22 pm (utc) on Jan. 15, 2009]
[edit reason] disabled graphic smileys ;) [/edit]