Casey,

You are right.  This is not homework.  I was just
trying to see how I could condensed the code.  At the
Perl conference this past month, I took the 'Repair
Shop' tutorial with Mark-Jason Dominus and I am just
trying to incorporate what I learned.

Thank you for your support. 


--- Casey West <[EMAIL PROTECTED]> wrote:
> On Tue, Aug 07, 2001 at 05:42:55PM -0400, Bob
> Showalter wrote:
> : > -----Original Message-----
> : > From: Sophia Corwell
> [mailto:[EMAIL PROTECTED]]
> : > Sent: Tuesday, August 07, 2001 5:24 PM
> : > To: Casey West
> : > Cc: [EMAIL PROTECTED]
> : > Subject: Re: Hashes with multiple values per key
> : > 
> : > 
> : > Thanks for the reply eventhough my question was
> not
> : > clear.
> : > 
> : > Let me explain what I am trying to do.
> : > 
> : > I have a hash named %orgjobs whose keys have
> multiple
> : > values.
> : 
> : Nitpick, but a hash entry cannot have multiple
> values. It can
> : only have a single scalar value. Now that value
> can be a reference
> : to an array (or hash), which can itself have
> multiple values.
> : Your data below is a hash of references to arrays.
> : 
> : > The keys are department numbers and the
> : > values are job_titles.  There is a also a text
> file
> : > that has a list of departments, users, and the
> users'
> : > job titles.  I want a report that shows the
> : > departments and the job titles in that
> department. 
> : > For example:
> : > Dept 100: Engineer, Scientist
> : > Dept 200: Programmer, Manager
> : > Dept 300: Secretary, Student
> : > 
> : > A dept 100, for example, can have more than one
> : > engineer and more than one scientist.  However,
> the
> : > report just need to show one.
> : > 
> : > So this is what I did in perl....
> : > 
> : > $found = 0;
> : > foreach $job (@{$orgjobs{$dept}}) {
> : >    if ($job eq $job_title) {
> : >        $found++;
> : >    }
> : > }
> : > if ($found == 0) {
> : >     push(@{$orgjobs{$dept}},$job_title);
> : > }
> : 
> : This code adds the job title to the list for that
> department if
> : it doesn't already exist. This code works, and
> there are ways to
> : streamline it somewhat, but you could make your
> life much easier
> : by using a hash of job titles for each department
> instead of an 
> : array of job titles.
> : 
> : So you would do something like this in place of
> all the code
> : above:
> : 
> :    $orgjobs{$dept}{$job_title}++;
> : 
> : Now %orgjobs is a hash, keyed on department, with
> values of
> : references to hashes, keyed on job title. The
> value of this
> : hash is the number of employees with that job
> title in that
> : department (if you care).
> : 
> : To print your report, you would do something like
> this:
> : 
> :    for my $dept (sort keys %orgjobs) {
> :       print "Dept $dept: ", join(', ', sort keys
> %{$orgjobs{$dept}}), "\n";
> :    }
> : 
> : Make sense? Oops, now I did your homework for you.
> Hope you get
> : a good grade! :)
> 
> That's not very nice dude.  I don't get the
> impression this is
> homework and even if I did I would at least give her
> the binefit of
> the doubt.  If you think it's homework, ask before
> you post code.  At
> least give her the honor of being able to be honest
> with the list.
> 
> You had a pretty good answer up till that cheap
> shot.  :-(
> 
>   Casey West
> 
> -- 
> Shooting yourself in the foot with VMS 
> $ MOUNT/DENSITY=.45/LABEL=BULLET/MESSAGE="BYE"
> BULLET::BULLET$GUN
> SYS$BULLET
> $ SET
>
GUN/LOAD/SAFETY=OFF/SIGHT=NONE/HAND=LEFT/CHAMBER=1/ACTION=AUTOMATIC/
> 
>   LOG/ALL/FULL SYS$GUN_3$DUA3:[000000]GUN.GNU
> $ SHOOT/LOG/AUTO SYS$GUN SYS$SYSTEM:[FOOT]FOOT.FOOT 
> 
> %DCL-W-ACTIMAGE, error activating image GUN 
> -CLI-E-IMGNAME, image file $3$DUA240:[GUN]GUN.EXE;1 
> -IMGACT-F-NOTNATIVE, image is not an OpenVMS Alpha
> AXP image
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to