in reply to Re: Using File::ReadBackwards or equivalent on pre-existing file handle
in thread Using File::ReadBackwards or equivalent on pre-existing file handle

p.s. am I better unshifting the lines then doing a print(FH) foreach (@arr); or pushing the lines then doing a print(FH) foreach (reverse @arr);? I suppose I'm asking, is pushing faster than unshifting (I assume yes), and does perl make a new array copy when it does a foreach (reverse ...), or is it clever enough just to iterate backwards over the array. I presume it's clever...

Replies are listed 'Best First'.
Re^3: Using File::ReadBackwards or equivalent on pre-existing file handle
by Anonymous Monk on Jun 26, 2014 at 00:57 UTC

    To sure, profile & benchmark the variations.

     print ... for reverse @list will generate a new, complete list I think (currently cannot find the right B magic to produce the optree display supporting the claim).

Re^3: Using File::ReadBackwards or equivalent on pre-existing file handle
by Laurent_R (Canon) on Jun 26, 2014 at 06:19 UTC
    Difficult to say without testing. I think that slurping the file from the FH directly into an array will be slightly faster than pushing or unshifting it line by line. Then poping the lines to be printed might be faster than using reverse, but only a benchmark can really say. You might even get diffrent results with differents versions of Perl. Overall, the difference is likely to be small or almost unsignificant.