View difference between Paste ID: DFsU1RUZ and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Cwd; | |
6 | ||
7 | ||
8 | sub get_path { | |
9 | my $path; | |
10 | ||
11 | if (!(@ARGV)){ | |
12 | $path = cwd(); | |
13 | } | |
14 | else { | |
15 | foreach my $e(@ARGV){ | |
16 | if($e =~ m/(\-d(\w+))/gi){ | |
17 | $path = $2; | |
18 | } | |
19 | else { | |
20 | $path = cwd(); | |
21 | } | |
22 | } | |
23 | } | |
24 | ||
25 | return $path; | |
26 | ||
27 | } | |
28 | ||
29 | sub get_files { | |
30 | my $path = shift @_; | |
31 | ||
32 | my @directory; | |
33 | ||
34 | opendir(my $dh, $path) or die $!; | |
35 | while(defined(my $e = readdir $dh)){ | |
36 | next if ($e =~ /^\.\.?$/); | |
37 | if (-d "$path/$e"){ | |
38 | # print "$path/$e\n"; | |
39 | push (@directory,"$path/$e"); | |
40 | } | |
41 | } | |
42 | close $dh; | |
43 | ||
44 | get_files($_) for @directory; | |
45 | ||
46 | open_directory(@directory); | |
47 | } | |
48 | ||
49 | sub open_directory { | |
50 | ||
51 | my @files; | |
52 | ||
53 | foreach my $d(@_){ | |
54 | ||
55 | opendir (my $dh, $d)or die " '$d' $!"; | |
56 | while(my $e = readdir $dh){ | |
57 | if ($e =~ /\.htm/gi){ | |
58 | push(@files,"$d/$e"); | |
59 | } | |
60 | }closedir $dh; | |
61 | } | |
62 | ||
63 | open_files(@files); | |
64 | ||
65 | } | |
66 | ||
67 | sub open_files { | |
68 | ||
69 | my @files = @_; | |
70 | my @lines; | |
71 | foreach (@files){ | |
72 | print "$_\[1\]\n"; | |
73 | } | |
74 | ||
75 | foreach my $f (@files){ | |
76 | print "$f\[2\]\n"; | |
77 | open(my $fh,'<',$f) or die " '$f' $!"; | |
78 | print "$fh\[3\]\n"; | |
79 | push(@lines,<$fh>); | |
80 | close($fh); | |
81 | } | |
82 | ||
83 | extract_data(@lines); | |
84 | } | |
85 | ||
86 | sub extract_data { | |
87 | ||
88 | my @lines = @_; | |
89 | my @emails; | |
90 | ||
91 | foreach my $line(@lines){ | |
92 | while($line =~ /(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/gi){ | |
93 | push(@emails,$1); | |
94 | } | |
95 | } | |
96 | return @emails; | |
97 | } | |
98 | ||
99 | ||
100 | my $path = get_path(); | |
101 | my @emailsa = get_files($path); | |
102 | ||
103 | foreach my $n(@emailsa){ | |
104 | print "$n\n"; | |
105 | } |