beanscake has asked for the wisdom of the Perl Monks concerning the following question:
Hello forks i want to write script that will scan given folders for email and write them to a file, i know am doing it wrong i would appreciate enlightenment thanks below is my poor code
use strict; use warnings; use 5.010; use POSIX qw(strftime); use List::MoreUtils qw(uniq); use Data::Dumper qw(Dumper); my $range = 50; my $minimum = 100; my $random_number = int(rand($range)) + $minimum; my $date = strftime "Y%m%d", localtime; my $filenadme =$exname.$random_number.$date.'.txt'; @files = </Users/beanscake/Download/*>; #scan folders for email foreach $file (@files) { open (MYFILE, $file); open(my $fh, '>', $filenadme); while (<MYFILE>) { chomp; my @emails = split(' '); my @filtered = uniq(@emails); foreach my $emails (@filtered) { if($emails =~ /^\w+\@([\da-zA-Z\-]{1,}\.){1,}[\da-zA-Z-]{2 +,6}$/) { print $fh "$emails\n"; print "$emails\n"; } } } close $fh; close MYFILE; print "done\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help! on this piece of code.
by NetWallah (Canon) on Mar 26, 2015 at 04:19 UTC | |
Re: Need help! on this piece of code.
by Dumu (Monk) on Mar 26, 2015 at 10:26 UTC | |
Re: Need help! on this piece of code.
by Dumu (Monk) on May 06, 2015 at 09:33 UTC |