Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: Problem with splice in a 2D ARRAY

Reply
Thread Tools

Re: Problem with splice in a 2D ARRAY

 
 
gamo
Guest
Posts: n/a
 
      06-17-2013
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,


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with splice in a 2D ARRAY gamo Perl Misc 6 06-17-2013 08:57 PM
Help with printing a bit pattern with printf and %x matt.jaffe@gmail.com C Programming 9 04-19-2013 12:14 PM
splice an array into another array agendum97@gmail.com Javascript 1 06-26-2008 12:02 AM
Array function SPLICE doesn't work with Select->OPTIONS array. JavaScript BrianP Javascript 2 09-18-2005 04:20 AM
splice or split an array Peter Perl Misc 3 09-08-2004 09:31 AM



Advertisments