in reply to Re^2: Saving an array to a disk file
in thread Saving an array to a disk file

Hard to be sure. The join generates a large string that is output as one large write (maybe). The foreach (possibly) generates a large number of small writes. For file I/O one large write (the join) generally is much better than a large number of smaller writes (the foreach).

On the other hand, if the string gets so large it starts swapping out to disk, then the join is likely to be much worse.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: Saving an array to a disk file
by chromatic (Archbishop) on May 26, 2006 at 06:21 UTC

    Are you not forgetting about IO buffering in the writing example? I expect the file layer to write one block at a time, regardless of how large or small each individual print is, unless you've disabled buffering.

Re^4: Saving an array to a disk file
by meraxes (Friar) on May 26, 2006 at 04:02 UTC

    I hadn't thought of the file I/O issue. Very good point.

    When I started using Perl I was munging 1Gb files so I was assuming that the array was very big. :-)

Re^4: Saving an array to a disk file
by blazar (Canon) on May 26, 2006 at 10:39 UTC

    Hard to be sure. The join generates a large string that is output as one large write (maybe). The foreach (possibly) generates a large number of small writes. For file I/O one large write (the join) generally is much better than a large number of smaller writes (the foreach).

    On the other hand, if the string gets so large it starts swapping out to disk, then the join is likely to be much worse.

    And how 'bout good 'ol ($\,$,)?!?