in reply to Buffered IO and un-intended slurping

I don't have a better answer for you than the one you already thought of--$/ getting undef'd--but it strikes me that with < 600MB, you'd get far better performance by slurping the whole file into memory.

If you loaded it into a scalar and then opened that scalar as a ram-file, you needn't change your existing code, but it would run perhaps 2 orders of magnitude or more, more quickly.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"
  • Comment on Re: Buffered IO and un-intended slurping

Replies are listed 'Best First'.
Re^2: Buffered IO and un-intended slurping
by Wiggins (Hermit) on Jan 02, 2010 at 14:25 UTC
    My first thought was "how do I seek() on a scalar?" Buy you mention "opened that scalar as a ram-file" which seems to imply there is a way to do just that
    How about a pointer to the method?

    It is always better to have seen your target for yourself, rather than depend upon someone else's description.

      See open for details:

      open my $fhFile, '<', 'theFile' or die $!; my $slurpedFile; { local $/; $slurpedFile = <$fhFile>; } close $fhFile; ## Supplying a reference to a scalar as the filename ## initiates the opening of a ram file. open my $fhRam, '<', \$slurpedFile or die $!; ## Now file operations on $fhRam will read from the slurped scalar my $firstLine = <$fhRam>; ...

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.