By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

Remove (use strict) from this snippet

P: 30
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
Share this Question
Share on Google+
6 Replies


eWish
Expert 100+
P: 971
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
Expert Mod 2.5K+
P: 3,503
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

P: 30
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 mys or whatever else), to make it run under use strict. I ll take it from there.

Thanx
VirtualWeb
Oct 21 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
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 mys 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
Expert 100+
P: 971
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
Expert 100+
P: 174
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

Post your reply

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