> -----Original Message-----
> From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 16, 2001 11:54 AM
> 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.
Your sub looks ok, but of course we can't tell if any of
the regexes are actually matching.
Instead of ${$href}{'UserID'}, which is valid syntax, the
preferred idiom is:
$href->{UserID}
which is a bit easier to read.
>
> 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);
This is a symbol glob, which predates the availability of
references. Don't use that. Stick with references.
>
> What's that all about? How are items in %hashname referenced (or
> dereferenced as the case may be) in mysub()?
You're doing it correctly, so the problem must be
somewhere else. Step through your code in the debugger.
>
> --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]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]