I am working on making a simple program that reads a file and does these things:
Counts the amount of lines that have "ing" in them
Counts the amount of lines that begin with a capital letter
Counts the amount of lines that begin with a space
Counts the amount of lines that end with a period
Counts the amount of lines that have words that begin with b and end with s
Counts the amount of lines that have "tt" somewhere in them
I know there should be a simple coding method to this, but cannot find it in my books. If anyone can help me, I'd really appreciate it! Here's what I have so far:
init();
dPrint();
exit (0);
sub init()
{
open(TT, $ARGV[0]) or die "Can't open $ARGV[0]. \n";
@lines = <TT>;
close(TT);
}
sub dPrint()
{
my @words = split /\s+/, join("",@lines);
my %wc = ();
foreach my $word (@words)
{
if ($word =~ /ing/)
{
$wc($word)++
}
}
print "----\tWord \tCount ----\n";
foreach my $word (sort {$a cmp $b} keys %wc)
{
print "\t$word\t$wc{$word}\n";
}
}
Counts the amount of lines that have "ing" in them
Counts the amount of lines that begin with a capital letter
Counts the amount of lines that begin with a space
Counts the amount of lines that end with a period
Counts the amount of lines that have words that begin with b and end with s
Counts the amount of lines that have "tt" somewhere in them
I know there should be a simple coding method to this, but cannot find it in my books. If anyone can help me, I'd really appreciate it! Here's what I have so far:
init();
dPrint();
exit (0);
sub init()
{
open(TT, $ARGV[0]) or die "Can't open $ARGV[0]. \n";
@lines = <TT>;
close(TT);
}
sub dPrint()
{
my @words = split /\s+/, join("",@lines);
my %wc = ();
foreach my $word (@words)
{
if ($word =~ /ing/)
{
$wc($word)++
}
}
print "----\tWord \tCount ----\n";
foreach my $word (sort {$a cmp $b} keys %wc)
{
print "\t$word\t$wc{$word}\n";
}
}