Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Out of memory error!!!

by sathya83aa (Acolyte)
on Mar 28, 2013 at 08:12 UTC ( #1025886=note: print w/replies, xml ) Need Help??

in reply to Re: Out of memory error!!!
in thread Out of memory error!!!

Hi McA,

Thanks for those suggestions..Even after changing the foreach to while, I'm still facing the same Out of memory issue :-(

Any suggestions?

Thanks & Regards,

sathya V.

Replies are listed 'Best First'.
Re^3: Out of memory error!!!
by Corion (Pope) on Mar 28, 2013 at 08:16 UTC

    If you're still running out of memory, you'll have to find out where you are storing your data and maybe not store all the data in RAM. If you are storing the bulk of your data in a hash, an easy way of trading time for space is to use DB_File or some other key/value store that can be tied to a hash. Update: Also see Tie::DBI, which just had a new release out.

    Often it also helps to output progress through your file so that you get an idea where in your program you run out of memory.

Re^3: Out of memory error!!!
by McA (Priest) on Mar 28, 2013 at 08:35 UTC

    In your example you're opening a filehandle named XML, so I assume you want to convert your input stream to xml format. If this is right we would like to see how the xml output is produced. Probably you're using a memory intensive way.


      Ok Let me make it more clear..Im fetching those variables from a flat file and printing it in the XML file. The order of printing of the variable will differ from how we are getting the variable.


      open (my $INFO, "<", "$File") or die("Cannot open the flat file $!");

      open(my $LOG,">>LOG_file") or die("Cannot open $!");

      open(my $XML,">xml_file") or die("Cannot open $!");

      while (defined(my $line2 = $INFO)) {

          $line2 =~ s/&/&amp;/g;

          print "$line2\n";

          my $segment = substr($line2,0,2);

          if($segment eq "00")


          my $Var1 = trim(substr($line2,40,8));


          if($segment eq "A0")


          $Var2 = trim(substr($line2,2,9));

          $Var3 = trim(substr($line2,14,3));

          $Var4 = trim(substr($line2,20,42));

          $Var5 = trim(substr($line2,62,30));

      and so on


          print XML "<Header>\n";

          print XML "<AAA>VAR1<\/AAA>\n";

          print XML "<BBB>VAR2<\/BBB>\n";

          print XML "<CCC>VAR3<\/CCC>\n";

        print XML "<DDD>VAR4<\/DDD>\n";

        print XML "<EEE>VAR5<\/EEE>\n";

          print XML "<Header>\n";

      close $LOG;

      close $XML;

      close $INFO;

      sub trim($)


         my $string = shift;

          $string =~ s/^\s+//;

         $string =~ s/\s+$//;

         return $string;


        How much data do you have to collect to decide in which order you can generate the xml? Do you have to collect all records of the input file? Do you only have to collect a sequence of segments to create a - let's call it - xml record? Sorry, but your excerpt didn't help?

        How big is the input file?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025886]
[Corion]: ambrus: Well, usually, these people don't have in their description "mail me at dodgy_reseller # g m a i l | co m" , replace the "#" by "@" :)
[Corion]: Oh, and the "o" in "com" is a zero
choroba orders a camera from Ole Scæmmer
[ambrus]: Corion: ah. that's different. the ones I mean are selling at reputable sites like ebay that usually filters scammers out pretty quickly (as well as filters a lot of legitimate users who then get annoyed that the biggest providers exclude them)
[Corion]: ambrus: Yeah, if you provide the plausible story of "got it as a gift", buying that via Ebay might somewhat work. But I consider Ebay another harbor of scammers ;)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-11-21 15:07 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (304 votes). Check out past polls.