What is the key to your hash: UserID. Then you would use the UserId value as
the key and either setup something like:
$hash{$userid}[0] - support id
$hash{$userid}[1] - Assigned to
$hash{$userid}[2] - DateOpened
I also like the -> when doing the work from a ref:
${$href}{'UserID'} becomes $href->{$userid}[0] = 1
Not sure about the *hashname either.
You could save off the userid from above and then populate using the $userid.
You should have
userid and/or supportid, assignedto, dateopen. If there is a setup of this
flow, then you would clear the userid after te dateopen and if more data comes in
without first a userid then error. If a userid can have multiple values, then you
could do something like:
$href->{$userid}[0] .= $1 . ';';
This would would allow for mutiple values etc.
I guess the first thing is "What are you after? Then put together a hash
and/or array to get what you need."
Wags ;)
-----Original Message-----
From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 16, 2001 08:54
To: Wagner-David; '[EMAIL PROTECTED]'
Subject: RE: Populating a referenced hash
My mistake on $hash{'$UserID'}. I found that and fixed it shortly after
sending the message, but it still doesn't allow me to populate the hash with
values.
If I were doing this in C, I'd send a structure pointer to the sub/function
and get back a the various populated fields.
I saw this done a while ago with a hash, but it was using a convention
something like:
&mysub(*hashname);
What's that all about? How are items in %hashname referenced (or
dereferenced as the case may be) in mysub()?
--Chuck
> -----Original Message-----
> From: Wagner-David [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 16, 2001 10:29 AM
> To: 'Tomasi, Chuck'; '[EMAIL PROTECTED]'
> Subject: RE: Populating a referenced hash
>
>
> Your print using:
> print "User ID = $hash{'$UserID'}\n";
> will use $UserID, but there is no such thing.
>
> In your sub, you are allowing only one value per
> assignment, ie your keys are UserID, AssignedTo, etc and
> there will be only one value. If you want multiple values,
> then will need to do concatentation, but if you are trying to
> keep this all together, this may or may not work.
>
> To see the values you have, use:
> foreach (keys %hash) {
> printf "%3d %20s\n",$hash{$_}, $_; # prints the hash
> value, hash Key
> }
>
> Wags ;)
>
> -----Original Message-----
> From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 16, 2001 07:29
> To: '[EMAIL PROTECTED]'
> Subject: Populating a referenced hash
>
>
> Perl: 5.6.0
> OS: Solaris 7
> Goal: Scan a text file for key words/values and populate a hash
>
> My parsing works, but the main() never sees the values
> properly. If I'm
> passing by reference, why isn't the hash I passed getting
> populated in the
> main namespace?
>
> Thanks
>
> --Chuck
>
> ----------arg.pl---------------
> #/usr/plx/bin/perl -w
>
> use strict;
>
> sub ref
> {
> my ($href, $aref) =@_;
> my (@leftovers);
>
> foreach (@$aref) {
> chomp;
> if (/^UserID\s+:\s+(\d+)/) {
> ${$href}{'UserID'} = $1;
> } elsif (/^SupportGroup\s+:\s+(\d+)/) {
> ${$href}{'SupportGroup'} = $1;
> } elsif (/^Assigned To\s+:\s+(\d+)/) {
> ${$href}{'AssignTo'} = $1;
> } elsif (/^DateOpened\s+:\s+(\d+)/) {
> ${$href}{'DateOpened'} = $1;
> } else {
> push(@leftovers, "$_\n");
> }
> }
> return(@leftovers);
> }
>
> my @array;
> my @remains;
> my (%hash);
>
> open(F_TMP, "/tmp/tfile") || die("Cannot open text file");
> @array = <F_TMP>;
> close(F_TMP);
>
> @remains = &ref(\%hash, \@array);
> print "User ID = $hash{'$UserID'}\n";
> print "Remains = " . @remains . "\n";
> -----------output------------
> User ID =
> Remains = 2
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]