SPUG: Introducing me + dumb newbie question

Brian Wisti bwisti at hotpop.com
Thu Sep 23 08:37:56 CDT 1999

Hi Mike -
I don't know much Perl, but I think I know enough to help you out here.  Just
follow along...

> 2. Write a program that reads a series of words with one word per line until 
> end-of-file, then prints a summary of how many times each word was seen.
> #!/usr/bin/perl -w
> #typos are mine :)
> print "Please enter a few words, one word per line (^D to end)\n";
> chomp(@words = <STDIN>);
> foreach $word (@words) {
>    $count{$word}++;
> }
> foreach $word (keys %count) {
>    print "$word was seen $count{$word} times.\n";
> }
> If anybody can answer 1 or more of the following questions, it would be 
> wonderfully appreciated to the point where I may consider sending money:)
> 1. at which point is the %count actually created and what values are being 
> injected(I'm assuming numbers)?

Unless you are running with 'use strict' Perl creates your variables the first
time it sees them.  In the process, it sets them to an initial value that
makes sense (usually zero).

 > 2. does %count only contain keys? the book
mentioned nothing of this  functionality. 

A hash works like an array using words instead of index numbers to figure out
where things are.  The actual value of each key in this case if the number of
times it has seen the key word in our array of words.  As usual, Perl will
create the key if it hasn't already seen it, doing its "sensible value" magic. 
For each time it sees a word in the array, it increments the count for that
particular word.

> 3. is there a perl IDE available to set breaks and step through the code and
> view variable info intermittantly like Qbasic (lame i know)? 

There are a few out there.  Me, I'm still teaching myself about how to use the
debugging tools (too many years of inserting 'print STDERR "Debug Value:

>4. do I read the perldocs with man or perldoc? 

The easiest way to get through the perldocs is with perldoc <topic>

> 5. anybody have a jr. SA job available for a hard-working, fast learning, 
>enthusiastic person?

There's a lot out there.  I didn't think my skills were all that great, and I'm
going through the bizarre process of choosing which positions I want.

> If you've made it this far, thank you.  I look forward to meeting some of 
> you at the next meeting (if I'm still invited after sending this blatantly 
> self-serving message :)  I bow to the perl gurus.

Thanks for asking a question I could answer :)  The folks on this list are
incredible.  I learn a lot just lurking.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address

More information about the spug-list mailing list