At 4/3/2003 6:05 PM, [EMAIL PROTECTED] wrote: > ie I want to split up the array: > > array: 12345123451234512345 > > to: > > 12345 > 12345 > 12345 > 12345 > > I can do this easily just by printing to the file up till the correct > line length (5) and then inserting a "\n" and starting a new line. > > Now I want to essentially rotate the values by 90 degrees: > > 5555 > 4444 > 3333 > 2222 > 1111
Hi Tony, As long as your line length is constant, this'll do the trick. my $source = '12345123451234512345'; my $line_length = 5; # Convert $source into an array, e.g., # ( '12345', '12345', '12345', '12345' ) # Assumes that length($source) % $line_length == 0 my @array = $source =~ /\d{$line_length}/g; # Since we'll be looking at the individual digits # of each array element, we might as well convert # array elements into arrays of their digits, e.g., # ( [ 1..5 ], [ 1..5 ], [ 1..5 ], [ 1..5 ] ) @array = map { [ split // ] } @array; # This first for loop determines the order in which # digits from each array element are displayed for my $digit_index (reverse 0..$line_length-1) { # On each line, print the $digit_index'th digit # of each element foreach my $elem (@array) { print $elem->[$digit_index]; } print "\n"; } Cheers, David