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";
The beginning of knowledge is the discovery of something we do not understand.
Frank Herbert (1920 - 1986)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.