in reply to How do I just count any words from a file?
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Usage: $0 <input_file>"; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $ +!"; my ($line_cnt, $word_cnt, $char_cnt); while (<$fh>) { chomp; $line_cnt++; $char_cnt += length($_); my @word = split " ", $_; $word_cnt += @word; }
Cheers - L~R
|
|---|