in reply to Speed of opening and closing a file 1000s times

Update: Hrm, I guess I'm a very slow typer today.

Opening and closing files once for every line? Why in the world would you want to to that? Consider the following:

#!/usr/bin/perl -w use strict; my $line; open INPUT_FILE, "input_filename" or die "Wonky!\n"; open FIRST_FILE, ">filename1" or die "Hork!\n"; open SECOND_FILE, ">filename2" or die "Foo!\n"; open THIRD_FILE, ">filename3" or die "Spew!\n"; while ($line = <INPUT_FILE>) { if $line =~ /first_criteria/ { print FIRST_FILE $line; } else if $line =~ /secod_criteria/ { print SECOND_FILE $line; } # And so on. }

But I have no idea where the @natures array comes from. Is that your criteria for sorting the lines?