1

I would like to push data to a multi-dimensional array in Perl

such as quality_list[i][j] using:

  push(@quality_list, $string_list, $qp); 

But, I think, I could not use it. Could you help me about it?

@se1s = ('1','5','8');
@se2s = ('3','2','4');

sub test()
{
foreach $se1(@se1s)
  {
  foreach $se2(@se2s)
    {

    push(@quality_list, $se1, $se2); 

    }
  }
}

I expect such as:

quality_list[1][0] = 1
quality_list[1][1] = 3


quality_list[2][0] = 5
quality_list[2][1] = 2
3
  • Provide a runable example with Input and expected output Commented Jan 13, 2016 at 10:32
  • Thanks, please see the revised version. Commented Jan 13, 2016 at 10:48
  • Your array starts at zero. What's the first row of @quality_list expected to be? Commented Jan 13, 2016 at 11:29

1 Answer 1

4

It's not really clear what you want. But this seems to get the results that you ask for.

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Data::Dumper;

my @se1s = ('1','5','8');
my @se2s = ('3','2','4');

my @quality_list;

foreach (0 .. $#se1s) {
  push @{$quality_list[1]}, $se1s[$_];
  push @{$quality_list[2]}, $se2s[$_];
}

say Dumper \@quality_list;

I think that reading "perldoc perldsc" will be very useful for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.