Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Updated Safe 2.1 Solution
palindromic dates
Sea
Perl
testing dereference of anonymous routines
Perl programs
Perl - Sort hash of filenames by file extension
Basics
Jeffy John Sam (101724)
matrx travarsal
Please log in to post a comment.