#!/usr/bin/perl # TODO: # 1. input file on command line # 2. output to a file use strict my ($buf, @temp_file, @in_file, @out_file, $first, $second, $third, $openme, $length, $pad_file, $count, $max_length, $t, $u, $v, $size); $max_length = 1000000; print ("\nfile : "); $openme = ; $count = 0; open(IN,"$openme") || die "Sorry. Couldn't open: $!\n"; # Use this if you don't want spaces to be included # while (read (IN, $buf, 1)) { # # if (($buf eq " ") or ($buf eq "\t")) # { # $buf = "\n"; # } # # if (($buf ne "\n") && ($count < $max_length)) # { # $count++; # $in_file[$count] = $buf; # } # } # the default is to include spaces. Tabs are converted to spaces. while (read (IN, $buf, 1)) { if ($buf eq "\t") { $buf = " "; } if (($buf ne "\n") && ($count < $max_length)) { $count++; $in_file[$count] = $buf; } } $length = $count; print ("\nlength is : $count\n"); close (IN); print ("t-dimension : "); $t = ; print ("u-dimension : "); $u = ; print ("v-dimension : "); $v = ; $size = ($t*$u*$v); print ("\nsize is : $size\n"); if ($size < $length) { print ("\nsize is smaller than the file. Proceeding anyway.\n"); } if ($size > $length) { $count = 0; print ("\nsize is larger than the input. Pad file: "); $pad_file = ; open(IN,"$pad_file") || die "Sorry. Couldn't open: $!\n"; # Use this if you don't want spaces to be included # while (read (IN, $buf, 1)) { # # if (($buf eq " ") or ($buf eq "\t")) # { # $buf = "\n"; # } # # if (($buf ne "\n") && ($count < $size)) # { # $count++; # $in_file[$count] = $buf; # } # } # the default is to include spaces. Tabs are converted to spaces. while (read (IN, $buf, 1)) { if ($buf eq "\t") { $buf = " "; } if (($buf ne "\n") && ($count < $max_length)) { $count++; $in_file[$count] = $buf; } } close (IN); $count = 0; open(IN,"$openme") || die "Sorry. Couldn't open: $!\n"; # Use this if you don't want spaces to be included # while (read (IN, $buf, 1)) { # # if (($buf eq " ") or ($buf eq "\t")) # { # $buf = "\n"; # } # # if (($buf ne "\n") && ($count < $size)) # { # $count++; # $in_file[$count] = $buf; # } # } # the default is to include spaces. Tabs are converted to spaces. while (read (IN, $buf, 1)) { if ($buf eq "\t") { $buf = " "; } if (($buf ne "\n") && ($count < $max_length)) { $count++; $in_file[$count] = $buf; } } } close (IN); $count = 0; for ($first = 1; $first <= $t; $first++) { for ($second = 1; $second <= $u; $second++) { for ($third = 1; $third <= $v; $third++) { $count++; $temp_file[$first][$second][$third] = $in_file[$count]; } } } $count = 0; for ($third = 1; $third <= $v; $third++) { for ($second = 1; $second <= $u; $second++) { for ($first = 1; $first <= $t; $first++) { $count++; $out_file[$count] = $temp_file[$first][$second][$third]; } } } $count = 0; for ($count = 1; $count <= $size; $count++) { print ($out_file[$count]); if ($count % 70 == 0) { print ("\n"); } } print ("\n\n");