Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use Cwd;
- sub get_path {
- my $path;
- if (!(@ARGV)){
- $path = cwd();
- }
- else {
- foreach my $e(@ARGV){
- if($e =~ m/(\-d(\w+))/gi){
- $path = $2;
- }
- else {
- $path = cwd();
- }
- }
- }
- return $path;
- }
- sub get_files {
- my $path = shift @_;
- my @directory;
- opendir(my $dh, $path) or die $!;
- while(defined(my $e = readdir $dh)){
- next if ($e =~ /^\.\.?$/);
- if (-d "$path/$e"){
- # print "$path/$e\n";
- push (@directory,"$path/$e");
- }
- }
- close $dh;
- get_files($_) for @directory;
- open_directory(@directory);
- }
- sub open_directory {
- my @files;
- foreach my $d(@_){
- opendir (my $dh, $d)or die " '$d' $!";
- while(my $e = readdir $dh){
- if ($e =~ /\.htm/gi){
- push(@files,"$d/$e");
- }
- }closedir $dh;
- }
- open_files(@files);
- }
- sub open_files {
- my @files = @_;
- my @lines;
- foreach (@files){
- print "$_\[1\]\n";
- }
- foreach my $f (@files){
- print "$f\[2\]\n";
- open(my $fh,'<',$f) or die " '$f' $!";
- print "$fh\[3\]\n";
- push(@lines,<$fh>);
- close($fh);
- }
- extract_data(@lines);
- }
- sub extract_data {
- my @lines = @_;
- my @emails;
- foreach my $line(@lines){
- while($line =~ /(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/gi){
- push(@emails,$1);
- }
- }
- return @emails;
- }
- my $path = get_path();
- my @emailsa = get_files($path);
- foreach my $n(@emailsa){
- print "$n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement