Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 14th, 2012, 09:50 AM
bgatto bgatto is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 10 bgatto User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 43 sec
Reputation Power: 0
Can perl end not printing to the web browser?

I have a form tha calla a perl script. All I want the script to do is validate the email address and send an email. No thing else. However, when I try this, I get an error, and the error goes away when I have a print command after everything like:

print "your email has been sent.\n";

And this prints on the same web page as my form.

Is there a way to end a perl script without printing anything at the end? If not, can I put that print in some sort of dialog box?

Reply With Quote
  #2  
Old September 14th, 2012, 10:04 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,085 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 51 m 10 sec
Reputation Power: 1809
A print command is not required. You'd need to show more of your script for us to understand where the error is coming from.

Reply With Quote
  #3  
Old September 14th, 2012, 10:39 AM
bgatto bgatto is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 10 bgatto User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 43 sec
Reputation Power: 0
Quote:
Originally Posted by keath
A print command is not required. You'd need to show more of your script for us to understand where the error is coming from.


Her is the code I'm using:

#!/usr/bin/perl -w

use CGI;

my(%frmFlds);
$buffer = "";

getFormData(\%frmFlds);

#################################
#
# Change these variables as needed.
#
#################################

$sendmail = "/usr/sbin/sendmail";
$from = "learneasymoney\@gmail.com";
$subject = "Thank you for your interest in $frmFlds{'product'}";

open(MAIL, "|$sendmail -t") || die "Cannot open mail sender.\n";

print MAIL "To: $frmFlds{'email'} \n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: text/html; charset=ISO-8859-1\n\n $frmFlds{'content'}\n";

close(MAIL);

sub getFormData {
my($hashRef) = shift;
$buffer = "";

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

foreach (split(/&/, $buffer)) {
my($key, $value) = split(/=/, $_);
$key = decodeURL($key);
$value = decodeURL($value);
%{$hashRef}->{$key} = $value;
}
}

sub decodeURL {
$_ = shift;
tr/+/ /;
s/%(..)/pack('c', hex($1))/eg;
return($_);
}

Reply With Quote
  #4  
Old September 14th, 2012, 11:17 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,647 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 53 m 20 sec
Reputation Power: 1170
Is this being called as an AJAX request?

First step is to add these 2 pragmas, which should be in every Perl script you write.
Code:
use strict;
use warnings;

Next, get rid of those 2 subroutines and instead use the methods provided by the CGI module to parse the submitted form data.

For validating the email, I'd use the Email::Valid module.

I prefer CGI's OO interface, so this how I'd begin the script.
Code:
#!/usr/bin/perl

use warnings;
use strict;
use CGI;
use Email::Valid;

my $cgi = CGI->new;
my %form_data = $cgi->Vars;

if ( Email::Valid->address($form_data{email}) ) {
    send_email();
}
else {
    # do something else
}


sub send_email {
    
    # send email using your preferred method
    # my preference would be to use one of the email modules on cpan
    # such as MIME::Lite
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Can perl end not printing to the web browser?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap