Hi all. I am a self-taught beginner Perl programmer. Run into this snippet of code which works as an Email List Cleaner. The script first checks the sintax of a list of emails saved in an input.txt file, then checks if those emails already exist in a sever file, lastly those emails which pass the first two test are verifyed whether they are true email boxes that exist in a remote server.
I installed the Net::validMX module in my server and this snippet works perfectly well all on its own. except that I need to embed this snippet in a existing script which do not (use strict)... and if I paste it as is.. it gives me errors.
What do ineed to strip off this snippet so it will work without use (strict)
--------------------------------------------------------------------------------------------------------- - use strict;
-
use Net::validMX;
-
-
-
my $mail_file = 'input.txt';#file with the emails
-
my $FILE;
-
-
my @valid_emails;
-
my @bad_emails;
-
my @repeated_emails;
-
my @undeliverable;
-
-
open (FILE, "$mail_file") || die "Can't open '$mail_file': $!\n";
-
my @emails = <FILE>;
-
close(FILE);
-
-
my %valid_emails;
-
-
foreach (@emails) {
-
chomp;
-
-
if( /\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}/ ){
-
$valid_emails{$_} = '1';
-
-
}
-
else{
-
push @bad_emails,$_;
-
}
-
}
-
-
my $server_file = 'saved.txt';
-
open (FILE, "$server_file") || die "Can't open '$server_file': $!\n";
-
my @existing_emails = <FILE>;
-
close(FILE);
-
-
foreach( @existing_emails ){
-
chomp;
-
if( $valid_emails{$_} eq '1' ){
-
delete($valid_emails{$_});
-
push @repeated_emails,$_;
-
}
-
}
-
-
my @passed_emails = keys(%valid_emails);
-
-
#check if mail ids are working
-
-
my ($rv, $reason, $sanitized_email);
-
-
foreach my $email (@passed_emails) {
-
-
my ($rv, $reason, $sanitized_email) = &Net::validMX::check_email_and_mx($email);
-
#print &Net::validMX::get_output_result($sanitized_email, $rv, $reason);
-
-
if( $rv ){
-
push @valid_emails, $email;
-
}
-
else{
-
push @undeliverable, $email;
-
}
-
-
-
}
-
-
-
$server_file = '>Valid_Emails.txt';
-
open (FILE, "$server_file") || die "Can't open '$server_file': $!\n";
-
-
foreach( @valid_emails ){
-
print FILE $_."\n";
-
}
-
-
close(FILE);
-
-
-
print "\nValid :\n";
-
-
foreach( @valid_emails ){
-
print $_."\n";
-
}
-
-
print "\nInvalid :\n";
-
foreach( @bad_emails ){
-
print $_."\n";
-
}
-
-
print "\nRepeated :\n";
-
foreach( @repeated_emails ){
-
print $_."\n";
-
}
-
-
print "\nUndeliverable :\n";
-
foreach( @undeliverable ){
-
print $_."\n";
-
}
-----------------------------------------------------------------------------------------------------------
Thanx beforehand
VirtualWeb
6 1625
Unless I don't understand what you are trying to do, if your code works with use strict, it should work without use strict.
What errors are you getting? I would not suggest that you remove the strict pragma.
--Kevin
I have to agree with eWish. If the code works fine on its own, then something is wrong with either the script you are putting it in or with the way you incorporated it.
Please know that "use strict" and "use warnings" are highly advised and a number of people here won't normally look at your code unless you do use them. They force you to correct syntactic and other such more minor errors before getting down to the real problem at hand.
As eWish said, you really need to let us know what error(s) you are seeing before we can tell you what is wrong.
Regards,
Jeff
Thank you guys for your comments.
When I code not using strict everything works for me.. when I add use strict to the code nothing works. I presume this is mainly because I never learned to initialize or what to initialize.
As I mentioned the snippet works fine on its own but when I try to customize or inbed into another script, it it gives me 500 errors. EXAMPLE instead of the script cleaning a List from a file I try to have it clean a list submitted by a form it doesnt work.
What I really hope is that you help me get this script to work stripping all the code that is added (all the my´s or whatever else), to make it run under use strict. I ll take it from there.
Thanx
VirtualWeb
Thank you guys for your comments.
When I code not using strict everything works for me.. when I add use strict to the code nothing works. I presume this is mainly because I never learned to initialize or what to initialize.
As I mentioned the snippet works fine on its own but when I try to customize or inbed into another script, it it gives me 500 errors. EXAMPLE instead of the script cleaning a List from a file I try to have it clean a list submitted by a form it doesnt work.
What I really hope is that you help me get this script to work stripping all the code that is added (all the my´s or whatever else), to make it run under use strict. I ll take it from there.
Thanx
VirtualWeb
To get it to work with strict you will certainly need the "my"s and such. Strict forces you to declare variables before they are used by prefacing them with my, or our, etc.
You still have not posted any errors nor any code. Without seeing either of those I don't know how we can help you. We cannot fly blind and be expected to help you fix your problem.
Regards,
Jeff
After a quick glance I don't see anything in the above code that would cause you a 500 error. But since you are embedding this code into another script, then there is no telling. We would need to see some of the code.
Did you upload the file in ASCII mode? Did you set the permission correctly? Are you printing the headers first?
--Kevin
After a quick glance I don't see anything in the above code that would cause you a 500 error. But since you are embedding this code into another script, then there is now telling. We would need to see some of the code.
Did you upload the file in ASCII mode? Did you set the permission correctly? Are you printing the headers first?
--Kevin
also are you using the shebang line ??
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pocm |
last post by:
Hi,
What's the property/value I need to set in css for A to mimic the
results of
<a href="..." target="_new">...</a>?
Cheers,
Paulo Matos
|
by: Joseph |
last post by:
I have a textBox that people writes stories in it. They can use
for format.
I have Aspell installed on the server, so people can make correction to
their text. Sometimes, they forget to add a...
|
by: Ron |
last post by:
I've got a listbox that holds a list of groups. Users can
select a group, hit the remove button and the group
should be removed from the listbox. The only problem is
that no matter which group you...
|
by: Charles Law |
last post by:
I have a form on which user controls are placed at runtime. When a control
is added to the form a handler is added for an event that a high-level
object raises, which must be handled by the new...
|
by: mistral |
last post by:
Need help to remove list of days from date script. Need format "June
07, 2006"
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// Get today's current date.
var now = new Date();
|
by: Daniel Mark |
last post by:
Hello all:
I have the following snippet:
In : fileName = 'Perfect Setup.txt\n'
In : fileName = fileName # remove the '\n'
character
In : fileName
Out: 'Perfect Setup.txt'
|
by: Russell Hoover |
last post by:
I want to make sure that no border (around a specific small "blog-button"
image) ever appears in FF or IE, or any other browswer. I couldn't seem do
it with xhtml, so I reverted to
border="0"
...
|
by: Sergei Shelukhin |
last post by:
Hi.
I have a <tdelement, with <ain it and <spaninside <a>, all
created statically (e.g. poresent in HTML when the page loads).
Later I execute the code that adds reference to td in question to a...
|
by: howa |
last post by:
Consider an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
a { background-color:red;}
</style>
</head>
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |