Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:04:34+00:00 2026-05-22T13:04:34+00:00

This is my code #!/usr/bin/perl -T use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard);

  • 0

This is my code

#!/usr/bin/perl -T

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use JSON;
use utf8;
use strict;
use warnings;


# ... ;

my $cgi = CGI->new;
$cgi->charset('UTF-8');

my @owners = map { s/\s*//g; $_ } split ",", $cgi->param('owner');
my @users  = map { s/\s*//g; $_ } split ",", $cgi->param('users');


my $json = JSON->new;
$json = $json->utf8;


my %user_result = ();
foreach my $u (@users) {
    $user_result{$u} = $db1->{$u}{displayName};
}

my %owner_result = ();
foreach my $o (@owners) {
    $owner_result{$o} = $db2{$o};
}

$json->{"users"}   = $json->encode(\%user_result);
$json->{"owners"}  = $json->encode(\%owner_result);

$json_string = to_json($json);

print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json_string;

and these lines

$json->{"users"}   = $json->encode(\%user_result);
$json->{"owners"}  = $json->encode(\%owner_result);

gives the error

Not a HASH reference

Why do I get that?

How can that be fixed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T13:04:35+00:00Added an answer on May 22, 2026 at 1:04 pm

    A JSON object (at least in the XS version, see below) is just a SCALAR reference, so you can’t perform a hash reference operation on it. In practice, most of the Perl objects you encounter will be hash references, but this will not always be the case.

    I’m not sure what you are trying to accomplish by using JSON to encode a JSON object. Do you need to encode the internals of the JSON object? Or do you just need to serialize the user and owner data? In the latter case, you should just use a new hash reference to hold that data and pass to JSON. If you really do require an encoding of the JSON object, you might have some better luck using JSON::PP (the “Pure Perl” variant of the JSON module), which does use a hash reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code: #!/usr/bin/perl -w use strict; use warnings; sub foo { return wantarray
This code triggers the complaint below: #!/usr/bin/perl use strict; use warnings; my $s =
I have this code: #!/usr/bin/perl use strict; use Tkx; my $mw = Tkx::widget->new('.'); $mw->g_wm_minsize(
I have this code which works. #!/usr/bin/perl use warnings; use strict; use Net::LDAP; use
I have this code #!/usr/bin/perl use strict; my @a = (b,a,d,c); my %h =
I have this code #!/usr/bin/perl -w use strict; use URI; use LWP::UserAgent; use Data::Dumper;
I have a code that works well here: #!/usr/bin/perl use strict; use warnings; use
#!/usr/bin/perl use strict; use warnings; sub paragraph { open my $file, <, dict.txt or
If I want do this with python,the code just like : #!usr/bin/python import os
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.