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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:59:14+00:00 2026-05-17T15:59:14+00:00

I am currently trying to pass a 32 by 48 matrix file to a

  • 0

I am currently trying to pass a 32 by 48 matrix file to a multi-dimensional array in Perl. I am able to access all of the values, but I am having issues accessing a specific value.

Here is a link to the data set:
http://paste-it.net/public/x1d5301/

Here is what I have for code right now.

#!/usr/bin/perl

open FILE, "testset.txt" or die $!;
my @lines = <FILE>;

my $size = scalar @lines;

my @matrix = (1 .. 32);
my $i = 0;
my $j = 0;
my @micro;

foreach ($matrix)
{
    foreach ($lines)
    {
        push @{$micro[$matrix]}, $lines;
    }
}
  • 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-17T15:59:15+00:00Added an answer on May 17, 2026 at 3:59 pm

    It doesn’t seem you understand that $matrix only indicates @matrix when it is immediately followed by an array indexer: [ $slot ]. Otherwise, $matrix is a completely different variable from @matrix (and both different from %matrix as well). See perldata.

    #!/usr/bin/perl
    use English;
    

    Don’t! use English–that way!

    This brings in $MATCH, $PREMATCH, and $POSTMATCH and incurs the dreaded $&, $`, $' penalty. You should wait until you’re using an English variable and then just import that.

    open FILE, "testset.txt" or die $!;
    

    Two things: 1) use lexical file handles, and 2) use the three-argument open.

    my @lines = <FILE>;
    

    As long as I’m picking: Don’t slurp big files. (Not the case here, but it’s a good warning.)

    my $size = scalar @lines;
    
    my @matrix = (1 .. 32);
    my $i = 0;
    my $j = 0;
    my @micro;
    

    I see we’re at the "PROFIT!!" stage here…

    foreach ($matrix) {
    

    You don’t have a variable $matrix; you have a variable @matrix.

        foreach ($lines) {
    

    The same thing is true with $lines.

            push @{ $micro[$matrix]}, $lines;
        }
    }
    

    Rewrite:

    use strict;
    use warnings;
    use English qw<$OS_ERROR>; # $!
    open( my $input, '<', 'testset.txt' ) or die $OS_ERROR;
    
    # I'm going to assume space-delimited, since you don't show
    my @matrix;
    # while ( defined( $_ = <$input> ))...
    while ( <$input> ) {
        chomp; # strip off the record separator
        # Load each slot of @matrix with a reference to an array filled with
        # the line split by spaces.
        push @matrix, [ split ]; # split = split( ' ', $_ )
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to pass an array that I have created in Javascript
Currently, I'm trying to pass a multidimensional array in Phonegap between two pages with
I am currently trying to by pass a proxy but the compiler is giving
I'm currently trying to pass PCI compliance for one of my client's sites but
Currently I am trying to pass some values through command line arguments and then
I'm currently trying to pass values using an AJAX request to a server side
I am currently trying to pass a generated JSON string to dojo for parsing
I am currently trying to create a function which will allow me to pass
Currently, I am trying to pass system X11 events (on Linux) to an object
I am trying to pass 2 values to a javascript xmlHttp request. The values

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.