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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:22:47+00:00 2026-06-10T09:22:47+00:00

I am able to create a matrix using this code #!/usr/bin/perl -w @arr1 =

  • 0

I am able to create a matrix using this code

#!/usr/bin/perl -w

@arr1 = (10,20,30);
@arr2 = (10,20,30);
@arr3 = (10,20,30);
@ref_arr = (\@arr1, \@arr2, \@arr3);

print"Prog starts\n";          

foreach $ref (@ref_arr) {
  #print @$ref->[0];
  foreach $val (@$ref) { 
    print "$val ";
  }
  print"\n";
}

Using the map function I can modify each value in the matrix like this

Example: increase every value by 1

foreach $ref (@ref_arr) {
  map($_++, @$ref);
} 

but I want to modify a certain row or a specific value, i.e. either add 1 to all of the second row’s values or to the first column of the second row

  • 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-10T09:22:49+00:00Added an answer on June 10, 2026 at 9:22 am

    You must always use strict and use warnings at the top of every program that you write. This applies especially if you are asking for help with your code, as these measures will reveal simple errors that you would otherwise overlook

    The map function is not for iterating over a list: it is for ‘mapping’ one list to another by applying a function to each element of the source list

    When you write

    map($_++,@$ref)
    

    you are building and discarding a copy of the values in @list. What you should write is

    $_++ for @$ref
    

    As for how to modify a single value out of the array, your array initialisation can be simplified to

    my @data = (
        [10, 20, 30], 
        [10, 20, 30], 
        [10, 20, 30]
    )
    

    I hope from this it is easier to see that the first 10 in the structure is accessible as $data[0][0] and, say, the last 20 is $data[2][1] (remembering that Perl arrays are indexed from zero). You can access and modifiy these values just as any ordinary scalar

    As for your particular examples, the second row is @{$data[1]} so you can increment every element of the row by writing $_++ for @{$data[1]}. The first column of the second row is incremented with $data[1][0]++

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

Sidebar

Related Questions

I'm able to create html links the following way: <a href=/about>About Us</a> This will
I'm able to create an excel file using apache poi. however, i want users
I am able to create a UIImage from a Core Animation layer using the
I am able to create a connection to a local sqlite3 database ( Using
I am able to create alternate dictation grammars using the dictation resource kit or
I'm looking into speeding up my python code, which is all matrix math, using
Recently I was able to create a tablet software for my Cerebral Palsy girl
Function constructors are able to create objects in javascript but I have a more
I am not able to create a jsTree inside of a jQuery UI tab.
I am able to create div tag dynamically but unable to create form tag

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.