...

View Full Version : The "Date" command



crca
07-29-2002, 09:47 AM
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:



#
# 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!

Benahimvp
07-31-2002, 11:43 AM
Straight from the Perldoc pages (http://www.perldoc.com/):

$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 (http://stein.cshl.org/WWW/software/CGI/). 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...

mr_ego
07-31-2002, 01:59 PM
simply place:



print FILE localtime();


that directly print the time.

Benahimvp
07-31-2002, 09:04 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum