Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Searching large files a block at a time

by JediWombat (Novice)
on Aug 02, 2017 at 02:04 UTC ( #1196496=note: print w/replies, xml ) Need Help??

in reply to Re: Searching large files a block at a time
in thread Searching large files a block at a time

Thanks Roboticus. I think I might have been unclear - what I want to avoid is reading line-per-line, as my code is very slow. I assume that's because of the while (my $buff = $z->getline()) loop, but feel free to correct me on this. Using this structure, my program takes a solid minute to run, whereas the shell script that does the same thing completes in a second or two. Maybe I could call bzcat from the system, and store its output in a variable? But I'm still not sure how to use while (<>) inside a full Perl program, when I'm not reading in from a pipe. Cheers, JW.

Replies are listed 'Best First'.
Re^3: Searching large files a block at a time
by Anonymous Monk on Aug 02, 2017 at 03:56 UTC
    Bunzip2's getline works just like <>; you can set $/ = "\n\n" to read in paragraph mode. It doesn't seem to be all that well optimized, though. You might try this:
    open my $BZ, "bzcat $file |"; while (<$BZ>) { ... }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1196496]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-05-26 16:29 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (93 votes). Check out past polls.