SPUG: Introducing me + dumb newbie question

Tim Maher/CONSULTIX tim at consultix-inc.com
Thu Sep 23 14:55:24 CDT 1999


>> Message submitted at: Thu Sep 23 12:55:24 PDT 1999
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 4013      

According to Michael Herrewig:
> 
> Hi,
> 
> First, I'd like to introduce myself.  My name is Mike Herrewig.  I've just 
> recently moved to Everett from Baraboo, WI.  I've been using information 
> systems since 1994 when I joined the Army.  Since, I have had experience 
> with almost everything.  If it has a monitor and keyboard I've probably used 
> it:)
> 
> A few weeks ago I began my rigorous perl self-education with "Learning Perl" 
> by the wonderful people at ORA.  I have no previous programming experience 
> besides a little BASIC(more specifically Qbasic), with a dash of Pascal and 
> some bash shell thrown in for flavor.
> 
> Anyway, here's my question pertaining to Chapter 5, Hashes.  Exercise 2 at 
> the end of the chapter challenged me to the point of total confusion.  I 
> tried for a couple of hours to figure it out myself before giving up and 
> looking at the answer in the back.  After seeing the answer I was even more 
> confused.  For those who don't have the book I'll include the exercise and 
> code below:
> 
> 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)?

Created when first seen, on the first pass through the foreach loop
The ++ tries to increment an existing value in the hash associated
with the $word key, but finds none, so the default value of 0 is
incremented, and left as the new value, on the first use of each $word.

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

%count contains key/value pairs, which you would see if you did "print %count"
Providing %count as the argument to the keys function (which is what
"keys %count" means) extracts the keys, only, from the hash, allowing them
to be provided as the list of values for the foreach() loop

> 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)?

Yup, Perl has a built-in debugger, which you get at by doing
"perl -d script-name"

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

In general, use man on UNIX, perldoc otherwise.

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

Sorry, no!

> 
> 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.

This is the kind of stuff this list is for!  

> -
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     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
> 
> 
> 

*==================================================================*
| Tim Maher, PhD  CEO, Consultix &    (206) 781-UNIX/8649          |
|      Pacific Software Gurus, Inc.   Email: tim at consultix-inc.com |
| "The UNIX/Perl Training Experts"    http://www.consultix-inc.com |
|Classes: 11/1 Shell/Utils  11/15 Adv Shell  12/6 LINUX  12/13 Perl|
*==================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    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