I'm sorry the responses here have come across as hostile, but to be honest, your presentation of the problem has been, um, problematic. (I'm truly grateful that someone -- you? -- fixed your original Out of memory. post; that entire thread is much easier to read now.)

I made some slight changes your program (as currently posted in the present thread), and it ran on a slightly modified version of the data provided in the earlier thread, with no "out of memory" problem.

I don't think my code changes had anything to do with memory management -- I just fixed the syntax errors, and changed to using STDERR for the status messages. In order to get it to work on the previously posted "postfix.txt" file (about 64KB), I had to delete the "." characters at the end of the data, in order to get past the "Bad $op ..." die condition.

#!/usr/bin/perl -w use strict; use warnings; $|=1; sub multiply { my( $ref1, $ref2 ) = @_; my @temp; for my $r1 ( @{ $ref1 } ) { for my $r2 ( @{ $ref2 } ) { push @temp, $r2 . $r1; } } return \@temp; } $/ = ','; my @stack; open POSTFIX, '<', 'postfix.txt' or die $!; while( my $op = <POSTFIX> ) { chomp $op; $op =~ tr/\r\n//d; ## remove any trailing newline if( $op eq 'x' ) { print STDERR "MULTIPLY\n"; push @stack, multiply( pop( @stack ), pop( @stack ) ); } elsif( $op eq '+' ) { print STDERR "ADD\n"; push @stack, [ @{ pop @stack }, @{ pop @stack } ]; } elsif( $op =~ m[^\d+$] ) { push @stack, [ pack 'v', $op ]; } else { die "Bad '$op' at position;" . tell( POSTFIX ); } } print STDERR "stacksize: " . @stack. "\n"; for my $item ( @stack ) { printf "%s", join ',', unpack 'v*', @{ $item }[ 0 ]; for my $group ( @{ $item }[ 1 .. $#$item ] ) { printf "+%s", join ',', unpack 'v*', $group; } print "\n"; }

With my version, you can redirect STDOUT to a file, and just see the status messages on your terminal. With a bash-like shell, you can also redirect STDERR to a separate file, which is what I did.

When the run finished successfully, the STDERR log file had 5170 lines containing "MULTIPLY" and 3966 lines containing "ADD", which happens to match the number of "x" and "+" characters in the data file, respectively. There were 30 elements in the "@stack" array, and 30 lines of data in the STDOUT file, the first two lines being:

1 2,5,6+2,4,6+2,3,6
The third line was over 8 KB long, the fourth line was:
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55
The fifth line was about 150 KB long, the 7th was 658 chars, the 28th was 228 chars, and all the rest had a single 4-digit number. The number on the 30th line was "9166", which is happens to be the number of digit strings in the postfix.txt input file.

I have no idea what this sort of output is supposed to mean. Perhaps I've missed something, but I think your statements about the intent of your program, and the nature of your approach, consist so far of the following:

I wrote a program to sybolically process multiplications on an equation in postfix notation. (taken from the first post)

The goal is to convert "if-then-else" statements in a 4th GL scripting language into equations. For example "if(a) {}elsif (b) {} else {}" would becomes (a+b+c).

Once accomplished all paths through the 4th GL script can be found by "multiplying" the equations through. For example, two simple if/else statements could be represented as (a+b)(c+d.) The independent paths throught the code is: ac+ad+bc+bd.

The code provided here does this equation transformation. The difficulty is that the equation is 64K in characters and will result in a couple million independent elements as a result.

Sorry -- not only do I fail to get a clear idea of the goal, but I really can't see any relation between that description and the output that I got from your script. For that matter, I'm clueless about what the output data provides, let alone what the input represents. Still, I hope the information I provided was helpful in some way.


In reply to Re: Out of Memory 2. by graff
in thread Out of Memory 2. by dneedles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.