Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
array flipper
#perl 5.22.1 my $arrayToFlip=[qw{..O.. .OOO. OOOOO ..O.. ..O..}]; flip($arrayToFlip,"ccw"); $arrayToFlip=[qw{12345 67890 ABCDE FGHIJ KLMNO}]; flip($arrayToFlip,"cw"); sub flip{ my $arr=shift; my $direction=shift; my $rows=scalar @$arr; my @flipped=(); if ($direction=~/^cw|ccw|lr$/){ foreach my $col(0..length $$arr[0]){ $flipped[$col]=""; foreach my $row(@$arr){ $flipped[$col].=substr($row,$col,1); }; $flipped[$col]=reverse ($flipped[$col]) if $direction eq "cw"; } @flipped=reverse @flipped if $direction =~/ccw/; } elsif ($direction eq 'v'){ @flipped=reverse (@$arr) } elsif ($direction eq 'h'){ my $row=0; foreach my $str(@$arr){ $flipped[$row++]= reverse ($str); }; } print $_,"\n" foreach (@flipped) }
run
|
edit
|
history
|
help
0
perl circle plot
Hashes
Array_with_shift_function
Cloeren 4 Coding
Interpolation_with_case_sensitive
PRAC 2 #5
101772
Challenge 41 Task 1
Updated Safe 2.1 Solution
main_objetos