in reply to Re^3: Parsing Large XML
in thread Parsing Large XML

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: Parsing Large XML
by marto (Cardinal) on Jul 06, 2010 at 19:06 UTC

    This isn't a code writing service and you seem to be ignoring advice you've been given about acquainting yourself with the basics of perl. Once again open.

    Update: See also How do I write to a file? or better still, as previously advised spend time learning the basics in the tutorials section or http://learn.perl.org.

      marto-

      I apologize for being lazy with my posting and not thoroughly reviewing my code before putting it on here. I realize also that I was not very clear with my question. I know how to use the open function, but don't know how I would use it here. If my code looks like this:

      foreach (@input2) { open (STDOUT, ">$outputfile"); print $_ if m#$criterion#; }

      Then the output file will only contain the matched result of the final iteration of the foreach loop. My question, then, is where in the code I could place the open function so that the result of every iteration is printed in the output file.

      Sorry to keep bothering you with this, and I will not ask any more questions regarding this code

      Thanks, shravnk

        "I know how to use the open function, but don't know how I would use it here."

        Clearly you don't because you still maing the same mistakes. You aren't checking for errors opening files, I've mentioned this three times already:

        Re: XML::Twig Help Re^3: XML::Twig Help Re^5: Parsing Large XML

        The open documentation explains the difference between opening for writing and appending. You also shouldn't be opening the file for each print. See also How come when I open a file read-write it wipes it out? from perlfaq5. A short example:

        #!/usr/bin/perl use strict; use warnings; my @input = qw( a b c d ); open(my $fh, '>', "output.txt") or die "cannot open input file $!"; foreach(@input){ print $fh "$_ \n"; } close($fh);