Re: Problem with splice in a 2D ARRAY

Discussion in 'Perl Misc' started by gamo, Jun 17, 2013.

  1. gamo

    gamo Guest

    for my $r (0..$#old) {
    my $row = $old[$r];
    for my $c (0..$#$row) {
    $new[$c][$r] = $$row[$c];
    }
    }

    I'm not sure it's possible to do that any more elegantly, given that you
    can't take a slice vertically through a 2d array.

    --------------------


    Well, that does a tansposition, and after that is posible to do the
    column swap:

    my @xy = @new;

    for $y (0,1){
    ($xy[0][$y],$xy[1][$y]) = ($xy[1][$y],$xy[0][$y]);
    }

    and redo the transposition. Or directly,

    for $x (0,1){
    ($xy[$x][0],$xy[$x][1]) = ($xy[$x][1],$xy[$x][0]);
    }

    Anyway, it could be done without splice. Thank you, I'll try to resume
    it to work with randomized small square matrix.

    Best regards,
     
    gamo, Jun 17, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter

    splice or split an array

    Peter, Sep 7, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    111
    Anno Siegel
    Sep 8, 2004
  2. BrianP
    Replies:
    2
    Views:
    287
  3. Replies:
    1
    Views:
    135
    Richard Cornford
    Jun 26, 2008
  4. gamo

    Problem with splice in a 2D ARRAY

    gamo, Jun 17, 2013, in forum: Perl Misc
    Replies:
    6
    Views:
    202
    Rainer Weikusat
    Jun 17, 2013
  5. Replies:
    2
    Views:
    164
    Charles DeRykus
    Jun 18, 2013
Loading...

Share This Page