SPUG: Introducing me + dumb newbie question
Mathew D. Watson
matw at halcyon.com
Thu Sep 23 14:54:51 CDT 1999
Finally, some questions I might be able to answer. ... Perl gurus please
take it easy on me if I've blundered.
1. %count is an associateve array (or hash). The statement that creates
%count is
$count{$word}++
I think it gets created when the interpreter first hits that statement, but
I'll let someone who really knows answer that.
2. No, %count contains both the keys and the values. I don't have perl up
and running right now, but here's something you can do to try and get a
feel for how associative arrays are structured:
@foo = %count;
print @foo;
You'll see both the keys and values (they won't look pretty though). Now if
someone can answer your question number 3., then you can examine @foo using
the debugger.
Good Luck!
Mat
At 11:13 AM 9/23/99 PDT, you wrote:
>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)?
>2. does %count only contain keys? the book mentioned nothing of this
>functionality.
>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)?
>4. do I read the perldocs with man or perldoc?
>5. anybody have a jr. SA job available for a hard-working, fast learning,
>enthusiastic person?
>
>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.
>-
>
>______________________________________________________
>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
>
>
----------------------------------------------------------------
Mathew D. Watson
matw at halcyon.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
More information about the spug-list
mailing list