Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 25 votes, 3.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2002, 08:47 AM   PM User | #1
crca
New Coder

 
Join Date: Jul 2002
Location: I forgot ;)
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
crca is an unknown quantity at this point
Post The "Date" command

I am using sambar server http://www.sambar.com and i would like to know how to print the servers date in the Perl File. My PL files content is:

Code:
#
# Tim's Perl Guestbook Version 1.00

$bookfile = "../docs/ts/guestbook.htm";

# Get the input
read(STDIN, $data, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $data);

foreach $pair (@pairs) 
{
	($name, $value) = split(/=/, $pair);

	# Convert the HTML encoding
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$value =~ s/<!--(.|\n)*-->//g;

	# Convert HTML stuff as necessary.
	$value =~ s/<([^>]|\n)*>//g;

	$FORM{$name} = $value;
}

# Verify that the required data has been received.
&missing_name unless $FORM{'name'};
&missing_email unless $FORM{'email'};
&missing_msg unless $FORM{'msg'};

# Read in the book for editing
# Note:  These actions on the book file should be atomic (flock()).
open (FILE, "$bookfile") || die "Can't open $bookfile: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

# Open book file
open (FILE, ">$bookfile") || die "Can't open $bookfile: $!\n";

for ($i = 0; $i <= $SIZE; $i++) 
{
	$_=$LINES[$i];

	if (/<!--top-->/) 
	{
		print FILE "<!--top-->\n";
   
		print FILE "<b>$FORM{'msg'}</b><br>\n";
		print FILE "$FORM{'name'}";
		if ($FORM{'email'})
		{
		print FILE "<div style=\"position: absolute; visibility: hidden\">$FORM{'email'}</div>";
		}

		print FILE "<HR>\n";
	}
	else 
	{
		print FILE $_;
	}
}

close (FILE);


# Response message.
print "<HTML><HEAD><TITLE>Thanks</TITLE></HEAD><BODY bgcolor=white>\n";
print "<FONT SIZE=5 COLOR=#996633><B>Thanks for your message</B></FONT>\n";
print "<BR><BR>Your entry has been added to our guest book:<HR>\n";
print "<b>$FORM{'msg'}</b><br>\n";
print "$FORM{'name'}";
print "<P><HR>\n";
print "<A HREF=\"/ts/guestbook.htm\">Back to GuestBook.</A><br>\n";
print "<A HREF=\"/ts/index.htm\">Back to Trowel and Sword home page.</A><br>\n";
print "</BODY></HTML>\n";

exit;


sub missing_name
{
	print "<HTML><HEAD><TITLE>Missing Name</TITLE></HEAD><BODY>\n";
	print "<FONT SIZE=5 COLOR=#996633><B>Name field is blank...</B></FONT>\n";
	print "<BR><BR>Please repost the name section of the guestbook.<P>\n";
	print "Return to the <a href=\"/ts/guestbook.htm\">Guest Book</a>.\n";
	print "</BODY></HTML>\n";

	exit;
}

sub missing_email
{
	print "<HTML><HEAD><TITLE>Missing Email</TITLE></HEAD>\n";
	print "<FONT SIZE=5 COLOR=#996633><B>Email field is blank...</B></FONT>\n";
	print "<BR><BR>Please repost the email section of the guestbook.<P>\n";
	print "Return to the <a href=\"/ts/guestbook.htm\">Guest Book</a>.\n";
	print "</BODY></HTML>\n";

	exit;
}

sub missing_msg
{
	print "<HTML><HEAD><TITLE>Missing Comments</TITLE></HEAD>\n";
	print "<FONT SIZE=5 COLOR=#996633><B>Comment field is blank...</B></FONT>\n";
	print "<BR><BR>Please repost the comment section of the guestbook.<P>\n";
	print "Return to the <a href=\"/ts/guestbook.htm\">Guest Book</a>.\n";
	print "</BODY></HTML>\n";

	exit;
}
So how could i do this??

Thanks in advance!
__________________
PM Me if you want the new URL for my forum!
crca is offline   Reply With Quote
Old 07-31-2002, 10:43 AM   PM User | #2
Benahimvp
New Coder

 
Join Date: Jul 2002
Location: H-Town
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Benahimvp is an unknown quantity at this point
Straight from the Perldoc pages:
PHP Code:
$now_string localtime;  # e.g., "Thu Oct 13 04:54:34 1994" 
You should also know that you are using an archaic method of parsing information from the query string. You should really look into using CGI.pm. It does all the work for you basically. Plus, you guaranteed that it's actually going to work with out bugs. There's no need to strip unwanted characters because it does it for you. Plus, it also lets you work with cookies, display HTML headers, print out forms, and much much more. Once you've moved to CGI.pm you'll wonder why you ever coded without it. Seriously...
__________________
-Ben Ilegbodu
(http://cmc.rice.edu/) & (http://bgo.netfirms.com/)
Benahimvp is offline   Reply With Quote
Old 07-31-2002, 12:59 PM   PM User | #3
mr_ego
Regular Coder

 
Join Date: Jun 2002
Location: Brisbane, Australia
Posts: 181
Thanks: 1
Thanked 0 Times in 0 Posts
mr_ego is an unknown quantity at this point
simply place:

Code:
print FILE localtime();
that directly print the time.
mr_ego is offline   Reply With Quote
Old 07-31-2002, 08:04 PM   PM User | #4
Benahimvp
New Coder

 
Join Date: Jul 2002
Location: H-Town
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Benahimvp is an unknown quantity at this point
Putting the "()" after localtime will print it out in seconds (a really long number). I'm pretty sure that without the "()" puts it ina text format.
__________________
-Ben Ilegbodu
(http://cmc.rice.edu/) & (http://bgo.netfirms.com/)
Benahimvp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:42 AM.


Advertisement
Log in to turn off these ads.