I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-04-25 13:30:51-07 by marcio
Extracting archives while using threads
Hi, I'm trying to extract zip files while using threads (using perl v5.10.0 on Windows XP), but every time I enable them the files are extracted to the current directory instead of the specified one. For example, using two files "x.zip" and "y.zip" each one with a directory inside it (with the same basename as the archive):
use strict; use threads; use utf8; use warnings; use Archive::Extract; use Cwd; use English; use File::HomeDir; sub do_stuff { my ($name) = @ARG; my $archive = new Archive::Extract(archive => "$name.zip"); $archive->extract(to => File::HomeDir->my_home); print "$name\n"; } die if getcwd eq File::HomeDir->my_home; my $use_threads = 1; my %data = ( x => \&do_stuff, y => \&do_stuff, ); if ($use_threads) { $data{$ARG} = threads->create($data{$ARG}, $ARG) for sort keys %data; $data{$ARG}->join() for sort keys %data; } else { $data{$ARG}->($ARG) for sort keys %data; }
If I set $use_threads to true then the files are extracted to the current directory, otherwise they are correctly extracted to the home directory. Is this a problem with my code? Thanks,
Direct Responses: Write a response