Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I add records to an existing matrix ?
where the elements being passed are variable e.g.
my $sv = "k"; my $sr = "l"; my $sj = "m"; my @X = ([qw(a b c)], [qw(d e f)], [qw(h i j)]); push @X,[qw($sv $sr $sj)];
This gives me
a b c d e f h i j $sv $sr $sj
Instead of what I was hoping for
a b c d e f h i j k l m

Replies are listed 'Best First'.
Re: add records to a matrix
by Velaki (Chaplain) on Nov 29, 2004 at 13:55 UTC

    If you take a look at the perlop page, you'll see that the qw operator does not interpolate variables.

    Therefore, the best way would probably be to eliminate the qw, and change

    push @X,[qw($sv $sr $sj)];
    to
    push @X,[$sv,$sr,$sj];

    Hope that helped,
    -v
    "Perl. There is no substitute."
      oops I shall RTFM more carefully in future
Re: add records to a matrix
by rinceWind (Monsignor) on Nov 29, 2004 at 13:47 UTC
    push @X,[$sv, $sr, $sj];

    --
    I'm Not Just Another Perl Hacker