Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect03_stdin1
#
# demo stdin-with-while shortcut
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 9-6-04
#######################################################

# better way to read each line into a hash...!

print "type in desired lines:\n";

while (<STDIN>)
{
    chomp($line = $_);

    if (exists $num_occurs{$line})
    {
        $num_occurs{$line} += 1;
    }

    else
    {
        $num_occurs{$line} = 1;
    }
}

print "\nEntered strings in ASCII order and their number \n";
print "   of occurrences\n";
print "-------------------------------------------------\n";
foreach $line (sort keys %num_occurs)
{
    print "$line:\t$num_occurs{$line}\n";
}

print "\nThe number of different strings read in: ", 
      scalar keys %num_occurs, "\n\n";


# end of lect03_stdin1