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 8363897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:18:03+00:00 2026-06-09T12:18:03+00:00

$a = {b=>{c=>1}}; # set up ref $b = $a->{b}; # ref the ref

  • 0
$a = {b=>{c=>1}};   # set up ref
$b = $a->{b};       # ref the ref
$b .= (d=>1,e=>1);  # where we want to assign multiple key/val at once

At the end of it $a should look like:

  • {
      'b' => {
               'c' => 1,
               'd' => 1,
               'e' => 1
             }
    };
    

At the end of it $b should look like:

  • {
      'c' => 1,
      'd' => 1,
      'e' => 1
    }
    

Note: it would be the same as doing:

$b->{d} = 1;
$b->{e} = 1;

$b = { %$b, d=>1, e=>1 }; Is not desired because it creates a copy of $a and loses the reference.

  • 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-06-09T12:18:04+00:00Added an answer on June 9, 2026 at 12:18 pm
    %{$b} = ( d => 1, e => 1 );
    

    You simply de-reference the anonymous hash-ref so it looks like a hash to the assignment operator.

    You could even do this:

    %{$b} = ( %{$b}, d => 1, e => 1 );
    

    In these cases %{$b} is just really a visual convenience (though in some cases can be a syntactic disambiguation) for %$b.

    …or you could do…

    foreach ( qw/ d e / ) {
        $b->{$_} = 1;
    }
    

    Obviously you’re probably not intending to assign the value of ‘1’ to everything. So how about a slice:

    @{$b}{ qw/ d e / } = ( 1, 1 );
    

    Slices are discussed in perldoc perldata, but there’s not really a good perldoc description of taking a slice of an anonymous hash. For that, you have to come to terms with all of the Perl documentation on references, and then extrapolate how to apply that to slice syntax. …or check anonymous hash slices at PerlMonks.

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

Sidebar

Related Questions

I have two Arrays of strings, and I would like to find the set
I want to store a cookie using something like Response.Cookies.Set(new HttpCookie(name,value); after I have
I have a cyclic graph I created using dosync and ref-set . When I
Set rs = conn.Execute(Statement) //rs has 6 fields I want to add the current
I want to have multiple objects share a reference through a private field, such
I want to set the attribute ref_id with _0 suffixed, but <xsl:attribute name=ref_id select=$id_0
I want to fetch a set of Posts w/ vote count listed, sorted by
I'm writing a PHP web service and one function. I want to set up
I want make a simple referral system. Basically referral URL structure something like this.
I have created a query block with begin/end and want to run that in

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.