in reply to Re: Array reference
in thread Array reference

Thank you moritz, actually I have many text files which I want to work through. My idea was, to process each file per loop with the same array and then to save the outcome (per reference) in different files. I have just tried it with my @Result declaration at the beginning i.e. above the loop. It works now! But: how can I empty this array if I start processing the next file? Thank you!

Replies are listed 'Best First'.
Re^3: Array reference
by moritz (Cardinal) on Jun 09, 2011 at 12:49 UTC

    Typically you would do something like this:

    for my $filename (@list_of_file_names) { process_file($filename); } sub process_file { my $filename = shift; open my $handle, '<', $filename or die "Can't open file '$filename' for reading: $!"; my @Result; while(<$handle>) { next unless $_ =~/\d+\schunk/; s/\s+/ /g; push @Result, $_."\n"; } # do something interesting with @Result here }
      Thank you very much moritz, I did not dare write a subroutine yet. I have learned a lot today.
Re^3: Array reference
by DStaal (Chaplain) on Jun 09, 2011 at 12:52 UTC
    @Result = (); # should empty your array for you.