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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:08:41+00:00 2026-05-27T14:08:41+00:00

I have a hash(%hash) with the following values test0 something1 test1 something test2 something

  • 0

I have a hash(%hash) with the following values

test0  something1
test1  something
test2  something

I need to build an array from the keys with the following elements

@test_array = part0_0 part1_0 part2_0

Basically, I have to take testx (key) and replace it as partx_0

Of course, I can easily create the array like the following

my @test_array;

foreach my $keys (keys %hash) {
    push(@test_array,$keys);
}

and I will get

@test_array = test0 test1 test2

but what I would like is to get part0_0 instead of test0, part1_0 instead of test1 and part2_0 instead of test2

  • 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-27T14:08:41+00:00Added an answer on May 27, 2026 at 2:08 pm

    Looks like a good time to use the non-destructive /r option for substitutions.

    my @array = map s/^test(\d+)/part${1}_0/r, keys %a;
    

    For perl versions that do not support /r:

    my @array = map { s/^test(\d+)/part${1}_0/; $_ } keys %a:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON object holding the following value: @value = {val:test,val1:test1,val2:test2} I want
I do the following my_hash = Hash.new my_hash[:children] = Array.new I then have a
I have the following ruby hash: values = [ {FA1: [{Act 1: A},{Act 2:
I have the following hash of countries; COUNTRIES = { 'Albania' => 'AL', 'Austria'
i have the following class test hash={} def printHash puts hash[1] puts hash[2] puts
According to MSDN , a hash function must have the following properties: If two
I have a hash table where the keys are rather complex lists, with sublists
I have a Perl hash whose keys start with, or are, numbers. If I
In perl, I have a hash that looks like the following: $hash{key1}->{a} = 1;
I have a Ruby hash with variables: a two-element array of strings an integer

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.