On Jan 16, 6:21 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
> [EMAIL PROTECTED] wrote:
> > On Jan 15, 10:57 am, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
> >> [EMAIL PROTECTED] wrote:
> >>> How do I change the value stored to a hash reference?
> >> C:\home>type test.pl
> >> my %hash = (
> >>      key => {
> >>          refkey => 'oldvalue',
> >>      },
> >> );
> >> print "$hash{key}->{refkey}\n";
> >> $hash{key}->{refkey} = 'newvalue';
> >> print "$hash{key}->{refkey}\n";
>
> >> C:\home>test.pl
> >> oldvalue
> >> newvalue
>
> >> C:\home>
>
> > I know how to change the value stored in hash, that isn't the
> > problem.  Here's a short example of the problem which fails...
>
> > use strict;
>
> > my %hash;
> > $hash{ 'key' } = 1;
>
> > $hash{ key }{ 'hoh' } = 'test';
>
> To be able to simplify a question adequately you need to have some idea
> of what the answer is going to be. Clearly your expectation is
> erroneous. Describe in English what data you want to store without
> reference to Perl and we will help.
>
> The value relating to a particular key stored in a hash is a scalar
> value. That value can be a simple integer or string, or a reference to a
> subsidiary hash or array.
>
> If the value 1 in your code above is meaningless and is simply there so
> that you can create the hash element then you can fix things by saying
>
>    $hash{'key'} = undef;
>
> which will enable Perl to autovivify the subsidiary hash when you make
> the second assignment.
>
> HTH,
>
> Rob

Thanks Rob, the undef is exactly what I needed!  I was originally
creating the hash with a value of "1" which told me that "work
package" would be used.  The work package could later not be used at
which point I would change the value to "0".  Later I altered my
script to just delete the work package the first instance is failed to
meet certain criteria.  As it passed through new filters in the script
(collecting data from an external source), I needed to add additional
information.  To get around the this problem I just created a new hash
to store everything.  So this now works...

"$workPackages{ $tempHash{ WORK_PACKAGE } }
{ $tempHash{ USE_ON_CODE } . '~~' . $useOnCodeCount } = \%tempHash;"

Thanks again Rob and everyone for the help.

-Philip


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to