in reply to Re: Statistics from a txtfile
in thread Statistics from a txtfile
#!/usr/bin/perl print("Please enter filename: "); $filename = <STDIN>; chomp ($filename); if ($filename=~m/^[_a-zA-Z][^.]{1,7}\.txt$/) { open (READFILE, $filename)|| die "Failed to open $filename: $!"; } my $filecontents; { local undef $/; $filecontents = <READFILE>; } close <READFILE>; #slurps the whole file into variable my @characters = $filecontents =~ m/./g; # puts a copy of each match + into @characters my $CharCount = scalar @characters; # this counts the number of + elements in @characters my @words = $filecontents =~m/\b\s/g; # number of words my @paragraph =($ # number of paragraphs. wha +t is code for new line char ie carriage return? my @sentences = $filecontents=~m/\.$/g; # number of sentences for (@characters){ print "$_ \n"; } # this will print a list +of each item counted: # output data # open(OUT, ">data1.txt") || die "data1.txt not open: $!"; # close(OUT);
|
|---|