On Tuesday 13 November 2007 09:55, [EMAIL PROTECTED] wrote:
> Folks,
Hello,
> I am having a problem dereferencing a hash and am hoping somebody can
> assist. I am getting the error:
It appears that you are actually having a problem creating a reference
to a hash.
perldoc perldata
perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref
> Can't use string ("napMD_ProgressCode") as a HASH ref
> while "strict refs" in use
>
> for the code below. I have tried various combinations of brackets
> and plus signs in the subroutine to dereference the HoH to no avail.
> Thanks in advance for setting me straight on how to do this properly.
>
>
> ==========
> use strict;
> my %napMD_ProgressCode = (
> 1 => {
> Code => 'ProgCd',
> Name => 'MD_ProgressCode',
> Definition => 'status of the dataset or progress of a
> review'
> },
> 2 => {
> Code => '001',
> Name => 'completed',
> Definition => 'production of the data has been
> completed'
> },
> 3 => {
> Code => '002',
> Name => 'historicalArchive',
> Definition => 'data has been stored in an offline
> storage facility'
> }
> );
> sub drawInputRowControlled{
> my $ControlList = $_[0];
> my %ControlList = %$ControlList; #Problem line
You are creating a copy of the hash. Why not just pass the whole hash
in the first place:
my %ControlList = @_;
> for my $i (sort keys %ControlList) {
> print qq{
> <input type="checkbox"
> name='status'
>
> value="$ControlList{$i}{Code}">$ControlList{$i}{Name}</option><br>
> }
> }
It you are using a scalar that contains a reference to a hash then you
don't need to make a copy of it, you can access it through the
reference:
for my $i (sort keys %$ControlList) {
print qq{
<input type="checkbox"
name='status'
value="$ControlList->{$i}{Code}">$ControlList->{$i}{Name}</option><br>
}
}
> }
>
> drawInputRowControlled('napMD_ProgressCode');
You are passing a string to your subroutine. You need to pass a
reference to the hash instead:
drawInputRowControlled( \%napMD_ProgressCode );
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/