[mplspm]: odd fix to transpose code memory problem
Nielsen, Aaron M
aaron.m.nielsen at intel.com
Mon Dec 3 16:02:44 CST 2001
Thanks for you're reply. I've found an interesting fix that I don't
understand. Maybe you could help explain. When I run a system call instead
of calling the almost identical sub my code runs fast with no Out of Memory!
errors.
system("Transpose.pl $in $temp1"); # instead of sub transpose($in,$temp1);
-------------Transpose.pl-----------------
#!/usr/bin/perl
open (IN, $ARGV[0]) || die "$!\n";
open (OUT,">$ARGV[1]") || die "$!\n";
while ( <IN> ) {
$j = 0;
chomp;
@_ = split //;
for ( @_ ) {
if ( $j > $linesm1 ) {
$line[$j] = ' ' x $i;
$linesm1++;
}
$line[$j] .= $_;
$j++;
}
for ( $j .. $linesm1 ) {
$line[$_] .= ' ';
}
$i++;
}
for ( 0 .. $linesm1 ) {
print OUT $line[$_],"\n";
}
------------transpose sub-------------------
transpose($file,$file_transposed);
sub transpose {
package transpose;
my (@ops) = @_;
my $linesm1 = undef;
my @line = undef;
my $j = undef;
my $i = undef;
open (IN, $ops[0]) || die "1 $!\n";
open (OUT,"> $ops[1]") || die "2 $!\n";
while ( <IN> ) {
$j = 0;
chomp;
@_ = split //;
for ( @_ ) {
if ( $j > $linesm1 ) {
$line[$j] = " " x $i;
$linesm1++;
}
$line[$j] .= $_;
$j++;
}
for ( $j .. $linesm1 ) {
$line[$_] .= ' ';
}
$i++;
}
for ( 0 .. $linesm1 ){
print OUT $line[$_],"\n";
}
close OUT;
close IN;
}
------------------------------------------------
Thanks
Aaron Nielsen PNG/CMO/PE&TE
503-712-1822
--------------------------------------------------
Minneapolis Perl Mongers mailing list
To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.
More information about the Mpls-pm
mailing list