473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Remove (use strict) from this snippet

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)

---------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use Net::validMX;
  3.  
  4.  
  5. my $mail_file = 'input.txt';#file with the emails
  6. my $FILE;
  7.  
  8. my @valid_emails;
  9. my @bad_emails;
  10. my @repeated_emails;
  11. my @undeliverable;
  12.  
  13. open (FILE, "$mail_file") || die "Can't open '$mail_file': $!\n";
  14. my @emails = <FILE>;
  15. close(FILE);
  16.  
  17. my %valid_emails;
  18.  
  19. foreach (@emails) {
  20.    chomp;
  21.  
  22.    if( /\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}/ ){
  23.        $valid_emails{$_} = '1';
  24.  
  25.    }
  26.    else{
  27.        push @bad_emails,$_;
  28.    }
  29. }
  30.  
  31. my $server_file = 'saved.txt';
  32. open (FILE, "$server_file") || die "Can't open '$server_file': $!\n";
  33. my @existing_emails = <FILE>;
  34. close(FILE);
  35.  
  36. foreach( @existing_emails ){
  37.     chomp;
  38.     if( $valid_emails{$_} eq '1' ){
  39.         delete($valid_emails{$_});
  40.         push @repeated_emails,$_;
  41.     }
  42. }
  43.  
  44. my @passed_emails = keys(%valid_emails);
  45.  
  46. #check if mail ids are working
  47.  
  48. my ($rv, $reason, $sanitized_email);
  49.  
  50. foreach my $email (@passed_emails) {
  51.  
  52.     my ($rv, $reason, $sanitized_email) = &Net::validMX::check_email_and_mx($email);
  53.     #print &Net::validMX::get_output_result($sanitized_email, $rv, $reason);
  54.  
  55.     if( $rv ){
  56.         push @valid_emails, $email;
  57.     }
  58.     else{
  59.         push @undeliverable, $email;
  60.     }
  61.  
  62.  
  63. }
  64.  
  65.  
  66. $server_file = '>Valid_Emails.txt';
  67. open (FILE, "$server_file") || die "Can't open '$server_file': $!\n";
  68.  
  69. foreach( @valid_emails ){
  70.     print FILE $_."\n";
  71. }
  72.  
  73. close(FILE);
  74.  
  75.  
  76. print "\nValid :\n";
  77.  
  78. foreach( @valid_emails ){
  79.     print $_."\n";
  80. }
  81.  
  82. print "\nInvalid :\n";
  83. foreach( @bad_emails ){
  84.     print $_."\n";
  85. }
  86.  
  87. print "\nRepeated :\n";
  88. foreach( @repeated_emails ){
  89.     print $_."\n";
  90. }
  91.  
  92. print "\nUndeliverable :\n";
  93. foreach( @undeliverable ){
  94.     print $_."\n";
  95. }

-----------------------------------------------------------------------------------------------------------
Thanx beforehand
VirtualWeb
Oct 19 '08 #1
6 1625
eWish
971 Expert 512MB
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
Oct 19 '08 #2
numberwhun
3,509 Expert Mod 2GB
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
Oct 19 '08 #3
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
Oct 21 '08 #4
numberwhun
3,509 Expert Mod 2GB
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
Oct 21 '08 #5
eWish
971 Expert 512MB
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
Oct 21 '08 #6
Icecrack
174 Expert 100+
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 ??
Oct 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
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
8
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...
4
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...
9
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...
9
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();
6
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'
21
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" ...
4
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...
4
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>
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
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...
0
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...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.