Thread Unterschiedliche MD5 Ergebnisse (35 answers)
Opened by Rambo at 2006-05-11 18:46

renee
 2006-05-18 15:01
#66016 #66016
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use strict;
use Digest::MD5;
use File::Find;
use threads;
use threads::shared;
#
#
# ------------------------------------------------------------------
# get time
# ------------------------------------------------------------------
my @time = localtime();
my $time_string = sprintf "%02d.%02d.%02d",
$time[5]+1900, $time[4]+1, $time[3],
$time[2], $time[1], $time[0];
#
#
# ------------------------------------------------------------------
# threads component
# ------------------------------------------------------------------
my $StopDotPrintFlag : shared;
sub DotPrintThread
{
my ($Interval, @Trash) = @_;
use IO::Handle;
autoflush STDOUT 1;
my $IntervalCount=0;
while ($StopDotPrintFlag != 2)
{
if ($StopDotPrintFlag == 1)
{
print STDOUT ".";
}
$IntervalCount++;
sleep $Interval;
}
return $IntervalCount;
}
#
#
# ------------------------------------------------------------------
# file details
# ------------------------------------------------------------------
my $directory = '.';
my $result_file = "md5_check_$time_string\.txt";
unlink ("$result_file");
#
my @files;
find(\&get_dir,$directory);
#
print "\n\tMD5_CHECK.PL powered by R.Hehlert\n";
#
#
# ------------------------------------------------------------------
# start threads
# ------------------------------------------------------------------
$StopDotPrintFlag = 0;
my $Interval = 1;
print "\n\tStarting 0% [";
my $DotPrintThread = threads->new(\&DotPrintThread, $Interval);
$StopDotPrintFlag = 1;
#
#
# ------------------------------------------------------------------
# start main programm
# ------------------------------------------------------------------
for my $file(@files)
{
my $md5 = Digest::MD5->new;
open FILE, $file->[0];
binmode(FILE);
while (<FILE>)
{ $md5->add($_);
}
my $digest = $md5->hexdigest;
close FILE;
open(my $fh, ">>$result_file") or die $!;
print $fh "Digest is $digest for $file->[1]\n";
close $fh;
}
#
#
# ------------------------------------------------------------------
# stop threads
# ------------------------------------------------------------------
$StopDotPrintFlag = 2;
my $NumberOfPrintedDots=$DotPrintThread->join;
print "\t] 100% applied time was ".$NumberOfPrintedDots*$Interval." seconds\n";
print "\n\tPls. read $result_file for results\n";
#
#
# ------------------------------------------------------------------
# get all files from all directorys
# ------------------------------------------------------------------
sub get_dir
{
push (@files,[$File::Find::name,$_]) if(-f $File::Find::name);
}
#
#END
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Unterschiedliche MD5 Ergebnisse