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

  • Home
  • SEARCH
  • 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 7626517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:20:09+00:00 2026-05-31T05:20:09+00:00

Here is the small code use List::Util qw(first); my $x = {FOO => undef};

  • 0

Here is the small code

use List::Util qw(first);

my $x = {FOO => undef};
my @array = (1,2,3,4,5,6,7,8,9);

$x->{FOO} =
    {
        'INFO' => first { $_ eq 1 } @array,
        'TI' => first { $_ eq 2 } @array,
    };

It’s not creating the nested hash – the anonymous hashref FOO has only one keypair. Here is the o/p

$VAR1 = {
          'FOO' => {
                     'INFO' => 1
                   }
        };

I am unable to figureout why is this happening? please help.

  • 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-31T05:20:10+00:00Added an answer on May 31, 2026 at 5:20 am

    The first function has the prototype of &@, which means that it takes a block and a list as arguments. Everything after the block is used as the list. Therefore your code is equivalent to:

    $x->{FOO} = {    
        'INFO' => first { $_ eq 1 } (@array, 'TI' => first { $_ eq 2 } @array),
    };
    

    You can either put the whole first expression in parens, or use an anonymous sub:

    $x->{FOO} = { 
        'INFO' => first(sub { $_ eq 1 }, @array),
        'TI'   => first(sub { $_ eq 2 }, @array),
    }; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem with interfaces. Here it is in Pseudo code :
I'm not going to get specific here with code, because I don't feel like
I am creating a small directory with links to scroll to the alphabetical list
I have a small piece of code that produce PrimeFaces dropdown List p:selectOneMenu ,
I'm having a small issue here: <div id=navbar> <ul id=navtabs class=floatcontainer> <li <?php if
I am stuck with a small problem here.. What i am trying to do
I've a small issue here. I am using an if statement with UIAlertView and
I'm getting crazy with a small problem here, I keep getting an error and
I want to do formatting using echo in shell scripting. Here is a small
Here is the situation: I am making a small prog to parse server log

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.