chris212 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use threads; use IO::Uncompress::Gunzip; use IO::Compress::Gzip; my $testfile = 'test.gz'; # create compressed file my $fh = new IO::Compress::Gzip($testfile); print {$fh} "$_ qwertyuiopasdfghjklzxcvbnm\n" foreach(1..5000); close($fh); print "$testfile created\n"; # read compressed file, starting a thread for every 500 lines $fh = new IO::Uncompress::Gunzip($testfile); my @chunk = (); while(my $line = <$fh>) { push(@chunk,$line); if(scalar(@chunk) == 500) { my $th = threads->create(\&test,\@chunk); @chunk = (); $th->join(); } } my $th = threads->create(\&test,\@chunk); $th->join(); close($fh); sub test { my ($lines) = @_; print foreach(@$lines); }
UPDATE:
We have restrictions on what software we can install (must be approved), so using a gzip executable on Windows isn't an option at the moment. Same with 7-zip if it even compresses a stream from STDIN. We ended up only using the script on Linux at the moment, so I'm just using the gzip command and compression will fail on Windows without it. If we get it approved on Windows, we can include the executable with the script, and it will be cross-platform.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Uncompress::Gunzip thread safe?
by BrowserUk (Patriarch) on Nov 21, 2016 at 19:11 UTC | |
by chris212 (Scribe) on Nov 21, 2016 at 20:23 UTC | |
by Corion (Patriarch) on Nov 21, 2016 at 20:42 UTC | |
by chris212 (Scribe) on Nov 21, 2016 at 21:55 UTC | |
by BrowserUk (Patriarch) on Nov 21, 2016 at 23:27 UTC | |
| |
by Corion (Patriarch) on Nov 22, 2016 at 08:12 UTC |