Charlotte Hee wrote:
>
> Hello,
Hello,
> I'm looking at the perl cookbook example on how to create a record data
> type:
>
> $record = {
> NAME => "Jason",
> EMPNO => 132,
> TITLE => "deputy peon",
> AGE => 23,
> SALARY => 37_000,
> PALS => [ "Norbert", "Rhys", "Phineas"],
> };
>
> # store record
> $byname{ $record->{NAME} } = $record;
>
> Is it possible to add another key:value-pair to $record *after* its
> already been saved in %byname? For example, if I want to add
> 'phone => 999-9999' to $record for Jason. How do I do that?
>
> I tried the following but it doesn't work and gives an error.
>
> $byname { $record->{"Jason"}->PHONE } = '999-9999'; # error undefined val
>
> I keep looking at the syntax but it's not sinking in.
$record is a reference to a hash so just add it directly to $record:
$record->{ PHONE } = '999-9999';
Or to access it via the %byname hash:
$byname{ Jason }{ PHONE } = '999-9999';
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>