The benchmark you did is misleading, and totally irrelevant to what I said.

Please go back and actually read the benchmark code in the little readmore tag there.

1. Your code, not exact, modified for clear comparison:

while (<FILE>) { push @lines, $_; }

This is a moderately less efficient version of the code in $subs{while_io} . The code in particular is

push @_,$_ while <$fh>;
2. My code,
@lines = <FILE>;
This is the code in $subs{list_io}. The code in particular is
@line= <$fh>;
They are two different animals, my version slurps the file, when your version does not. There is the performance difference.

Yes correct. The code in $subs{split_slurp} is measurably faster than either of the above solutions (for files that fit in memory and on my machine here). In addition both methods you mention are benchmarked. The second on small files moderately out performs the first. And split_slurp outperforms them both in similar conditions. Only while_io is suitable for really large files. And as the other posts mention, at least on Win32 Perl 5.6 list_io hangs on large files.

Your benchmark data is not relevant to my solution at all.

Your solution (insofar as <> in list context can be called your solution) is benchmarked along side two others. It is slower than one of the others according to the benchmark. What more is there to be said?

Benchmark: running list_io, split_slurp, while_io, each for at least 5 + CPU seconds... Rate while_io list_io split_slurp while_io 1629/s -- -5% -40% list_io 1722/s 6% -- -37% split_slurp 2725/s 67% 58% --
Update

Please don't add stuff to nodes and not put an update note on.

As for the size/slurp, my slurp is localized. It wont infect the rest of a script, furthermore the entire way through this discussion we have been discussing files that can be processed in memory Ie the 8.5MB word file, or $0 of the benchmark itself. The other use was a solution to do something in someones code where the effects of the localization, and reading in such a large file and then evaling it (!!?) practically required a notice that it was a bad solution. Here matters are much more constrained, and as such slurping isn't out of line. Consider the OP is using it happily right now (apparently).

Update 2

The original node there has been completely rewritten three times.

Thats way out of line dude. The community here is about sharing knowledge and having a good time. I posted a benchmark. You updated your node with a bunch of stuff that demonstratably not true in a least one instance. I called you on it. Fine. Somebody out there might learn something from this exchange. Get over it, and don't rewrite history because you made a mistake. If everyone did that the archives would be full of holes. Hell theres a few nodes I wish I didnt write. They are still here.

Anyway, since your rewriting history today this conversation is over.

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: Re^3: opening a file in a subroutine by demerphq
in thread opening a file in a subroutine by abhishes

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.