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

Hi exports, I have a Perl script that is working fine in Perl veriosn - v5.10.1, however, getting error in Perl various v5.26.1. Error message is "Can't use a hash as a reference" code snapshot mentioned below:

%rowRetrun->{contractList} = ""; %rowRetrun->{claimList} = (); %rowRetrun->{error} = ();

Replies are listed 'Best First'.
Re: Error : Can't use a hash as a reference
by Corion (Patriarch) on Nov 21, 2018 at 12:07 UTC

    You are using a hash: %rowRetrun as a reference: %rowRetrun->. This is not allowed in Perl.

    Maybe you meant to use $rowRetrun->... ?

      Hi Corion, when i run my code in perl 5.10 it gives me the results.
      atyagi@qtspg-1 ~$ perl perlHash.pl
      Using a hash as a reference is deprecated at perlHash.pl line 10.
      Using a hash as a reference is deprecated at perlHash.pl line 11.
      Using a hash as a reference is deprecated at perlHash.pl line 12.
      1.1 after method call $VAR1 = 'claimList';
      $VAR2 = undef;
      $VAR3 = 'error';
      $VAR4 = undef;
      $VAR5 = 'contractList';
      $VAR6 = '';

      same code i am runing in 5.26.1 its give me an error.
      Can't use a hash as a reference at perlHash.pl line 10.

      #!/usr/bin/perl -w # use strict; use warnings; use Data::Dumper; my %rowRetrun; %rowRetrun->{'contractList'} = ""; %rowRetrun->{claimList} = (); %rowRetrun->{error} = (); print "1.1 after method call ", Dumper(%rowRetrun);

        Again: That's not how you access a hash.

        Maybe you want:

        $rowRetrun{ 'contractList' } = "";