[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] New to Perl on Mac



According to Steve Lee Kelsch:
> 
> Hello, I have some simple MacPerl questions:

Hi ya!  :-)

> 1) I haven't been able to get the current date/time within a variable in 
> MacPerl. On UNIX, I used the date command: '$CURRENTDATE=`date 
> +%y/%m/%d`;'. How is it done on the Mac?

You should always use the localtime function - not a system
call.  Which is what the backtick does in this case.  Here
is some code:

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    $mon += 1;
    $curDate = sprintf( "%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $mon, $mday, $year, $hour, $min, $sec );

Notice that everything always counts from ZERO.  Whether it
be the seconds, minutes, hours, days, years, or whatever.
That is why $MON has one added to it.

> 2) Can an html web page include the contents of a MacPerl script's output?

Yes it can and no it can't.  Clear?  Like mud probably.
You can dynamically add in the contents of a MacPerl
script's output, but in order to do so you need to just
include it as part of your returning information.  Such
as:

	$theReply = <<END_HTML;
Content-type:	text/html

<html>
<head>
<title>My Page</title>
</head>

<body>
END_HTML

#
#	Do other stuff here.
#

	$theReply .= <<END_HTML;
blah blah blah....
END_HTML

	print $theReply;
	exit( 0 );

Notice that you can do things in between the various parts
of the HTML code and then include the results of your
programming into the HTML.  So yes, you can do this (in
MacPerl).

However, HTML has no facility for including other web pages
into itself on the fly.  So no - you can't do this (in
HTML).

> 3) Similarly, the ability to execute a MacPerl script from an html page 
> would be nice. Can it be done?

Yes it can.  As another person noted; simply download QPQ
from their web site.  Go to the TCP/IP control panel,
change the settings to look at AppleTalk, set your node id
to something like 1.1.1.1, and then boot up QPQ.  There
will be a LONG wait (like sometimes as long as 5 minutes)
while AppleTalk searches the network and waits for a
response from 1.1.1.1.  When the request times out finally,
AppleTalk will assume (correctly) that you really want to
BE that tcp/ip number and allow QPQ to come up.  All
messages/requests then sent to 1.1.1.1 will automatically
be routed to QPQ.  So in Netscape you would put something
like: HTTP://1.1.1.1/X/Y.html where X is the folder you
will have to put into QPQ's folder and Y.html is the web
page you want to run.  Perl scripts are saved as .CGI
files and referenced as http://1.1.1.1/X/Y.cgi.

> 4) Is there a way that I can test my scripts within Netscape on my local 
> (Mac) machine, without having to upload them to a server and accessing 
> them from the internet? I'd like to test them on my Mac through Netscape 
> as they would be seen to the public from a server over the internet. Is 
> this not possible without server software on my Mac?

See above.  The answer is the same for both question #3 and #4.


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch