At 4/3/2003 7:29 PM, [EMAIL PROTECTED] wrote:
> On Friday, April 4, 2003, at 12:48  PM, David Iberri wrote:
>> 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
> The values in those placings are completely arbitrary.

Hi Tony,

Ah yes... I should have been more generic in my approach anyhow :-)

Here's a general (but slightly more obfuscated) solution:

my $line_length = 5;
my @source = qw( 120 110 100 90 80 115 105 95 85 75 110 100 90 80 70 105 95
85 75 65 );

# Build a list of array refs, where each reference points to an
# array of $line_length elements from @source
my(@array_refs);
push @array_refs, [ splice @source, 0, $line_length ] while @source;

# Now print out a transposed version of @array_refs
for my $index (reverse 0..$line_length-1) {
  # On each line, print out the $index'th element of
  # each array reference within @array_refs
  print join(' ', map { $_->[$index] } @array_refs), "\n";
}

#
# Outputs:
#
#   80 75 70 65
#   90 85 80 75
#   100 95 90 85
#   110 105 100 95
#   120 115 110 105
#

That's probably closer to what you want, yes?

Cheers,
David

Reply via email to