Two of the print statements in your sample code appeared to be out of place, with one causing a compile failure. I modified it to the following:

#!/usr/bin/perl 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; chop $op if $op =~ tr[\n][\n]; ## remove any trailing newline if( $op eq 'x' ) { print "MULTIPLY\n"; push @stack, multiply( pop( @stack ), pop( @stack ) ); } elsif( $op eq '+' ) { print "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 "stacksize: " . @stack; 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"; }

Then I put the sample expression you provided "(a+b)(c+d.)" in a file named postfix.txt as follows:

(a+b)(c+d.)
and ran the script.

It produced the following output:

Bad '(a+b)(c+d.)' at position;12 at ./test.pl line 38, <POSTFIX> chunk + 1.

This isn't surprising as there is nothing in your code to handle the parentheses. Nor is there anything to handle the alphabetic characters, if it got past the initial parenthesis.

It also appears that your sample expression is infix but your code is written to work with postfix expressions.

As GrandFather said, it would be very helpful if you provided a small working sample of input to your program.

It appears that you are trying to produce a large number of combinations. With input of approximately 64K corresponding to nothing other than a series of simple if/else blocks, with something on the order of 4 characters per block, then you would have approximately 16K blocks. If I understand what you are doing correctly, you would then produce all combinations of either branch of each if/else statement. This corresponds to approximately 2**16384, a very large number indeed. You may find that producing and storing all possible combinations exceeds the capacity of your database.

In summary, you need to explore and understand the magnitude of the data set your are trying to produce before deciding how to store it.

Depending on what you want to do with the data once it is produced, you may find it is better to use and discard it as you produce it, rather than producing and storing it in one pass then reading and using it in another.

Update: I missed the link to Out of memory. and the sample data there. Now I see that the example expression in your post is not an example of intended input to your program but how about posting a small but complete sample input?


In reply to Re: Out of Memory 2. by ig
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.