#!/usr/bin/perl
use 5.008;
use strict;
use warnings;
use threads;
use threads::shared;
use Data::Dumper;
my %p1 :shared;
my %p2 :shared;
%p1 = (path => shift);
%p2 = (path => shift);
my @t;
push @t, threads->create(\&get_md5sums, \%p1);
push @t, threads->create(\&get_md5sums, \%p2);
$t[0]->join;
$t[1]->join;
print Dumper \%p1, \%p2;
sub doit_local {
local $_ = shift;
s/'/'\''/g;
return $_;
}
sub doit_my {
my $x = shift;
$x =~ s/'/'\''/g;
return $x;
}
sub get_md5sums {
my $x = shift;
print Dumper [$x, $$x{path}];
$$x{foo} = join " ", map '"'.doit_local($_).'"', 'find', $$x{path}, qw/-type f -exec md5sum {} ;/;
return 1;
}
####
[duelafn@jhegaala tmp]$ ./local_threads foo bar
$VAR1 = [
{
'path' => 'foo'
},
'foo'
];
$VAR1 = [
{
'path' => 'bar'
},
'bar'
];
$VAR1 = {
'path' => 'foo',
'foo' => '"find" "foo" "-type" "f" "-exec" "md5sum" "{}" ";"'
};
$VAR2 = {
'path' => 'bar',
'foo' => '"find" "bar" "-type" "f" "-exec" "md5sum" "{}" ";"'
};
####
[duelafn@jhegaala tmp]$ ./local_threads foo bar
$VAR1 = [
{
'path' => 'foo'
},
'foo'
];
Use of uninitialized value in substitution (s///) at ./local_threads line 25.
Use of uninitialized value in concatenation (.) or string at ./local_threads line 38.
$VAR1 = [
{
'path' => 'bar'
},
'bar'
];
Use of uninitialized value in substitution (s///) at ./local_threads line 25.
Use of uninitialized value in concatenation (.) or string at ./local_threads line 38.
$VAR1 = {
'path' => undef,
'foo' => '"find" "" "-type" "f" "-exec" "md5sum" "{}" ";"'
};
$VAR2 = {
'path' => undef,
'foo' => '"find" "" "-type" "f" "-exec" "md5sum" "{}" ";"'
};
####
[duelafn@jhegaala tmp]$ perl --version
This is perl, v5.8.4 built for i386-linux-thread-multi