Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Please clear this doubt,
Here NAME is a field of database. To fetch that value I think this is fine to do,
$crd=$ref->{$key}->{NAME};
To change the value of NAME, is it the right way?
$ref->{$key}->{NAME}=$new_name;

Replies are listed 'Best First'.
Re: Assigning value through references
by AK108 (Friar) on Oct 09, 2007 at 05:56 UTC
    Yes. Note that the second arrow is unneeded, due to the double-subscript rule of dereferencing:
    my $crd = $ref->{$key}{NAME}; $ref->{$key}{NAME} = $new_name;
    If you use strict and use warnings, then Perl will spot many invalid uses rather than silently converting them to symbolic references. See also perlreftut.
      Thank you for clarifying the doubt.
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Assigning value through references
by DrHyde (Prior) on Oct 09, 2007 at 10:01 UTC
    Depends on the database. If you're using, eg, DBM::Deep then yes, that'll work.

    If on the other hand $crd is the result of a SQL query using DBI, then you need to use SQL UPDATE to change a field's value.