#!/usr/bin/perl if ($#ARGV == -1) { print("Please enter filename: "); $filename = ; chomp ($filename); } else { $filename = $ARGV[0]; } if ($filename -r && $filename=~m/^[_a-zA-Z]/) #if filename is readable AND matches..... { open (READFILE, $filename)|| die "Failed to open $filename: $!"; } if ($filename !~ m/\.txt$/i) #if filename does not end with .txt then add to filename { $filename .= ".TXT"; } my $filecontents; { local undef $/; $filecontents = ; } close ; #slurps the whole file into a variable $sentences = 0; my @characters = $filecontents =~ m/./g; # puts a copy of each match into @characters my($ch); my $CharCount = scalar @characters; # this counts the number of elements in @characters my @words = $filecontents =~m/[a-zA-Z]\s/g;# matches a char followed by a white space character globally while ($ch = getc(READFILE)) { # count sentences: if ($ch eq "?" || $ch eq "!" || $ch eq ".") # if character is one of the three end of sentence markers { $sentences++; } } while ($ch = getc(READFILE)) { $CharCount { $ch }++; } for (@characters) { print "There are $_ \n characters"; } print "There are $sentences sentences"; # output data # open(OUT, ">data1.txt") || die "data1.txt not open: $!"; # close(OUT);