h1. range.pl code=yes #!/usr/bin/perl -wT my $num_args = $#ARGV + 1; if ($num_args != 3) { print "\nUsage: range.pl filename startcol endcol\n"; exit; } die "Startcol must be greater than 0." if ( $ARGV[1] < 1 ); my $data_file = $ARGV[0]; my $start_col = $ARGV[1] - 1; # first col in data file for substr cmd starts at 0 my $field_width = $ARGV[2] - $start_col; my %code_counts; open(my $fh, "<", $data_file) or die "Cannot open $data_file for read: $!"; while ( <$fh> ) { chomp; my $code_value = substr $_, $start_col, $field_width; if ( exists($code_counts{$code_value}) ) { $code_counts{$code_value}++; } else { $code_counts{$code_value} = 1; } } close($fh) or warn "Close failed: $!"; print "\nStart = $ARGV[1] End = $ARGV[2]\n"; print "Code : Count\n"; print "---- : -----\n"; foreach my $code_number ( sort keys %code_counts ) { my $result = sprintf("%4s : %4s\n", $code_number, $code_counts{$code_number}); print $result; }