That interests me less than the effect of throwing in the following:
sub multiplex { my @my_array; foreach my $entry (@array) { open my $fh => ">", $entry->[0].".mu" or die "open: $!"; push @my_array, [$fh, $entry->[1]]; } open my $fh => $file or die "open: $!"; while (<$fh>) { foreach my $entry (@my_array) { print {$entry->[0]} $_ if /$entry->[1]/; } } foreach my $entry (@my_array) { close($entry->[0]) or die "close: $!"; } }
After a couple of runs, it seems that the following is about what you get with multiple open filehandles that you juggle:
s/iter multiplex one multiplex 1.65 -- -87% one 0.209 690% --
which shows that not opening/closing multiple filehandles is a win, but it is much slower than repeated passes, and I have to wonder why. (One thing that I am wondering is how much caching files at the OS level could make a difference.)

For the record, my trial was done on Debian with Perl 5.8.1.


In reply to Re: Re: Speed of opening and closing a file 1000s times by tilly
in thread Speed of opening and closing a file 1000s times by seaver

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.