I am coding a simple program that counts the amount of lines in a file that have specific things, like the string "ing" or begins with a capital letter. My program runs without printing any output, just the top "Word Count" header. If anyone can see what I'm doing wrong, I'd appreciate the help, as I've been stuck on this for a few days now! Thanks!
---------------------------------
dPrint();
exit (0);
sub dPrint()
{
open( @lines,'tt') || die;
while (<@lines>)
{
my @word = split /\s+/, join("",@lines);
my %wc = ();
if ($word =~ /ing/)
{
$wc{$ing}++
}
if ($word =~ /^[A-Z]/)
{
$wc{$cap}++
}
if ($word =~ /^ /)
{
$wc{$space}++
}
if ($word =~ /\.$/)
{
$wc{$period}++
}
if ($word =~ /tt/)
{
$wc{$tts}++
}
}
print "----\tWord \tCount ----\n";
foreach my $ing (sort {$a cmp $b} keys %wc)
{
print "\ting = $wc{$ing}\n";
print "\tcap = $wc{$cap}\n";
print "\tspace = $wc{$space}\n";
print "\tperiod = $wc{$period}\n";
print "\ttts =$wc{$tts}\n";
}
}
---------------------------------
dPrint();
exit (0);
sub dPrint()
{
open( @lines,'tt') || die;
while (<@lines>)
{
my @word = split /\s+/, join("",@lines);
my %wc = ();
if ($word =~ /ing/)
{
$wc{$ing}++
}
if ($word =~ /^[A-Z]/)
{
$wc{$cap}++
}
if ($word =~ /^ /)
{
$wc{$space}++
}
if ($word =~ /\.$/)
{
$wc{$period}++
}
if ($word =~ /tt/)
{
$wc{$tts}++
}
}
print "----\tWord \tCount ----\n";
foreach my $ing (sort {$a cmp $b} keys %wc)
{
print "\ting = $wc{$ing}\n";
print "\tcap = $wc{$cap}\n";
print "\tspace = $wc{$space}\n";
print "\tperiod = $wc{$period}\n";
print "\ttts =$wc{$tts}\n";
}
}