Programming - Scripting Languages


From: Prototype <ouhengli@comp.nus.edu.sg>
Subject: how to automate...
Date: 14 Jan 1999 05:32:09 GMT

Any suggestion to automate the clicking of a button on
a html page??
This click will bring another similar page with a similar button. 
Need to click it again for at least 100 times.
From: Jenson Goh <gohcl@comp.nus.edu.sg>
Try onload function of Javascript if u dont need to pass data across html pages.

From: Choon Leong <chuacl@comp.nus.edu.sg>
Subject: Re: NRIC Check Digit Formula
Date: 21 Jan 1999 02:19:56 GMT

Below is a simple perl program for computing the check digit using the algo 
provided by Tiak Jung in the bbs (Dec 1996)

#!/usr/local/bin/perl5
# 
# Purpose: Compute the alphabet of a nric number

die "Usage $0 nric_no1 nric_no2 .. \n" if $#ARGV < 0;

%Check_Digit=(
	1 => A,
	2 => B,
	3 => C,
	4 => D,
	5 => E,
	6 => F,
	7 => G,
	8 => H,
	9 => I,
	10 => Z,
	11 => J );

@weights=(2,7,6,5,4,3,2);

while (@ARGV) {
	for($i=0,$sum=0;$i<7;$i++) {
		$sum += ($weights[$i] * substr($ARGV[0],$i,1));
	}

	$digit = 11 - ($sum % 11);
	print "Alphabet for nric no $ARGV[0] is $Check_Digit{$digit}\n";
	shift;
}

From: Phoenix Hawk <liewshia@comp.nus.edu.sg>
Subject: [perl] fast time-converter
Date: 21 Jan 1999 16:17:35 GMT

Anybody knows of a fast routine to convert a set of
date and time like this
"13/11/98, 12:34:00" to seconds (since epoch, or whatever).

I have about 6 millions or so records to convert,
so it's gotta be fast. :) 

Really appreciate any pointers. I have tried
looking at some of the Date modules like
Manip.pm and Date calc, manip is too darned
slow and Calc doesn't seem to have this
functionality. I have scanned the usenet,
but nothing of this sort.. :|
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 21 Jan 1999 18:55:51 GMT

POSIX.pm 's mktime() ?
From: valk <ngkaboon@comp.nus.edu.sg>
Date: 22 Jan 1999 00:54:47 GMT

: Anybody knows of a fast routine to convert a set of
: date and time like this
: "13/11/98, 12:34:00" to seconds (since epoch, or whatever).

pardon me what's since epoch (or whatever)
Have you tried Time::Local?
Time since Jan 1, 1970 (is that epoch?)
From: Lim Wee Cheong <limweech@comp.nus.edu.sg>
Date: 22 Jan 1999 07:23:46 GMT

how about setting up a hash table, then convert.
eg. if year is 98. year_seconds=645856886653
month is 4, month_seconds=3974234
day is 5, day_seconds=3942
if leapyear, then check if date after feb, add 1 day worth of seconds

oppps.. might as well use the "slow" method to set up a hash table.
(can write to file if you don't want to recalculate for every run)

lets say your records has 10 years worth of dates.
then you will have ~10*365 entries in your hash table.

then use this for your conversion.

for the hour and minutes, dunno if letting perl calculate faster or lookup
hash table faster.. check lor :)

hope this helps.. if it doesn't.. well.. i tried :)
From: Lim Wee Cheong <limweech@comp.nus.edu.sg>
Date: 22 Jan 1999 07:28:18 GMT

btw, if you can easily sort the records by date..
lets say 10,000 records for 13/11/98.
you lookup the number of seconds eg.4975397593 since whatever to 13/11/98
then for every record of this date, you only need to add the number of
seconds for the time.

are you doing some kind of y2k conversion work?
From: Lim Wee Cheong <limweech@comp.nus.edu.sg>
Date: 22 Jan 1999 18:42:37 GMT

i don't suppose your log files have more than 1 yr worth of data?
then the hash table will only have 365 entries.
for date "day - 2 char, month - 2 char, year - 2 char" total=6 char
for num of seconds, lets just assume 20 char.
26*365=9490 char to be stored in the table.. plus overhead for the table.
can't be very big at all.

to illustrate
$convert{"010198"}=3478347384;
$convert{"020198"}=3478347384+86400;
$convert{"030198"}="etcetc";

what i'm suggesting is, to use a hash lookup for your 6 million records,
instead of recalculating the number of seconds for each record.

but of course, if you can sort, then calculate once for date only for many
records of the same day. its okay also, but calculating and storing in a
hash table allows you to write the table to a file which you can read for
further runs. 

if you have 6 million records, i assume 6 mil. lines of url is it?
and you're worried about memory, you can split your big file into many
small files and run on several machines. you really don't have one big
file right? *grin*
eg. 1 yr worth of record, split into 365 files, using grep for date.

if its a once in a lifetime thingy, then you can ignore this post too :)
Good Luck, whatever it is you're doing.
From: valk <ngkaboon@comp.nus.edu.sg>
Date: 23 Jan 1999 01:59:48 GMT

I really hope you haven't tried WeeCheong method coz that's exactly
reinventing the time::local wheel.

time::local keep an internal cache of month starting time.

Anyway from the camel book
'...and return the number of seconds elapsed between January 1, 1970,
and the specified time.'

But I am not too sure how time are handled, when i try 
perl -e 'use Time::Local; print timelocal(0,0,0,1,1,1970),"\n";
returns
2649600

but the rest are all correct relatively.

From: DoCoMo <khoohuit@comp.nus.edu.sg>
Subject: [cgi script] how?
Date: 22 Jan 1999 11:00:35 GMT

hi!
i want to do the following:
1. user submit query
2. script gets query string
3. string pass to background program (eg. c++ program)
4. background program writes to a text file
5. script writes the textfile to screen (ie. in the browser)

how can i do this??

i have tried a simple example where i have this statement

<form method="GET"
action="http://www.comp.nus.edu.sg/~khoohuit/cgi-bin/form.perl.cgi">

blah, blah, blah...

when the user click the button send, it is suppose to execute
the script "form.perl.cgi" which simply just print some
statments.

why doesn't this work?
all i have instead is the actual script and not the result
of the script. 

i have set the permission of the directory to 755 and the
script to 755 too...

thanks for any advise!!
From: Two-Face <shihhsia@comp.nus.edu.sg>
Date: 22 Jan 1999 11:05:40 GMT

2> <form method="GET"
2> action="http://www.comp.nus.edu.sg/~khoohuit/cgi-bin/form.perl.cgi">
^^^^^^^^^^^^^^^^^^^^^^
thot u need to get permission to run cgi-scripts
in www2?
From: DoCoMo <khoohuit@comp.nus.edu.sg>
Date: 22 Jan 1999 11:20:34 GMT

: thot u need to get permission to run cgi-scripts
: in www2?

anyway out of this? 
i just want to submit a query and return some results.
if really cannot, then alternative :

1. run an applet to collect query
2. applet activates script/c
3. script/c writes to textfile, notify applet
4. applet load textfile

how to do the above?
From: ngcheepi@comp.nus.edu.sg (Dry Ice)
Date: Fri, 22 Jan 1999 12:48:22 GMT

>: thot u need to get permission to run cgi-scripts
>: in www2?

Unless it is a final year project .... normally, permission is not
granted to personal homepage.

What's yours?

> 3. script/c writes to textfile, notify applet
Firstly, the script needs write and execute access for this. If the
script don't have the execute right, applet cannot execute the script.

> 4. applet load textfile
Is the textfile in your account or the other person h/d?

From: WT<xuwantin@comp.nus.edu.sg>
Subject: A Question
Date: 26 Jan 1999 12:46:19 GMT

I wrote a perl program, and set to permission of this program to 6755.
(i.e. set the userid to this program.)
In this program, I called a sub function which is stored in another file
(call it c.pl). Therefore, inside the program, I wrote: require "c.pl";
To my surprise, the program runs on the web only when the permission is
755, but not 6755. And I found out that it is due to the require
line. 

Can anyone tell me why?
From: Phoenix Hawk <liewshia@comp.nus.edu.sg>
Date: 26 Jan 1999 16:13:20 GMT

When you run the perl script over the web, you are actually
executing it as "nobody" for most systems. Does nobody
has "read" access to your c.pl? 
That is, you need to set c.pl to 755 also...

On which machine are you running your perl script?
There should be a error log file used by the web server
to record errors, it would help you to debug your
program.

Do a 
tail -f /var/log/httpd-logs/error_log
on sununx to see what I mean...
From: WT<xuwantin@comp.nus.edu.sg>
Date: 27 Jan 1999 00:23:14 GMT

Sorry that I didn't explain my question clearly.

I had set the permission for both file to 6755. The reason is that I want
to access to my database on the web, so I set the userid for both files.

At the start, I set the permission of the main program to 755, and c.pl to
6755. But when I excute the sub function inside c.pl, I have the error
message saying that I am the user www-data, but not myself (userid= fyp).
So I thought that I should set the permission of the main program to 6755.
But I cannot even excute the program (I got the error message: Internal
server error.)

Later, I tried some testing programs, and found out that I cannot excute
my program whenever I use the require line in my program (i.e. when
executing some sub routine functions from another program which is the
main program.) And I wonder why!

I running my program on paella. It runs well when I use perl debugger,
but fails on the web.
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 27 Jan 1999 00:40:53 GMT

->But I cannot even excute the program (I got the error message: Internal
->server error.)

Whenever you have an internal server error check your server logs.

Tell us what your logs say. Anyway I've almost never used "require" 
before. Consider making c.pl into a module and "use" it instead. 

Does it run without the debugger i.e. from the commandline?
From: Choon Leong <chuacl@comp.nus.edu.sg>
Date: 27 Jan 1999 01:45:50 GMT

Phoenix Hawk <liewshia@comp.nus.edu.sg> wrote:
> When you run the perl script over the web, you are actually
> executing it as "nobody" for most systems. Does nobody

If suexec is used, it runs as the owner of the script. We are now using suexec
on www-appn.

From: dolphin <quahchin@comp.nus.edu.sg>
Subject: Matrix Computations in Perl
Date: 1 Feb 1999 02:18:48 GMT

Does anyone know where I can find a matrix computation
package (to compute the singular value decomposition) 
in Perl, besides the usual Perl ftp sites ?
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 1 Feb 1999 03:10:19 GMT

Perl's Math-MatrixReal-*.tar.gz at CPAN includes L-U(?) decomposition. 
Does that meet your requirements?  

From: DoCoMo <khoohuit@comp.nus.edu.sg>
Subject: [cgi] is it possible?
Date: 3 Feb 1999 06:18:43 GMT

is it possible for a browser screen to receive cgi output
from several sources at the same time?

or rather is it possible for several sources to output 
a file to a certain origin and the origin then output the
file to the browser screen? if yes, doesn't this pose a 
security risk?
Lim Wee Cheong <limweech@comp.nus.edu.sg>
Date: 3 Feb 1999 06:36:29 GMT

use java applet to read from several sources ?
(disclaimer: i don't know anything about java, just a suggestion)

if you dont have to use a browser, it would be easier. eg. use
lynx -source for each URL >> combined_urls.html
then lynx ./combined_urls.html

what are you trying to do?

From: Hopeless Romantic <kohseesh@comp.nus.edu.sg>
Subject: How to compile PERL in win95?
Date: 3 Feb 1999 11:56:19 GMT

Hi, I have downloaded the latest versionof PERL for win32 and I have
gunzipped the file and used "tar" to expand the program. However, I dunno
how to compile the thing using Visual C++ . Can anyone please tell me how
to compile PERL or mebbe tell me another way to compile it?
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 6 Feb 1999 01:20:31 GMT

If you want to compile *.pl into *.exe,
http://www.demobuilder.com/perl2exe.htm

If you want to compile PERL for win32, check out CPAN and read readme for
perl-bindist5.04(?)

IF you only want to use PERL for win32, check out Www.ActiveState.Com

From: neoyongt@cisacsg.iscs.nus.sg (Neo Yong Teck)
Subject: [cgi] how to write to file?
Date: 5 Feb 1999 15:27:49 GMT

i'm using perl to write a simple sentence to a file as below:

open(FILEA, ">abc.txt");
print FILEA "Line one\n";
close FILEA;
.
.

I managed to write to the file abc.txt by executing "perl a.cgi" on 
a unix command line. when i call a.cgi from a browser, it loads 
w/o error but the file abc.txt is not created in the dir on the server.
I tried specifying the full path name as open(FILEA, ">/..../abc.txt")
it still didn't work.
From: Lim Wee Cheong <limweech@comp.nus.edu.sg>
Date: 5 Feb 1999 15:40:21 GMT

check what uid the server is running under. see whether it changes to your
uid when your script is executed.

just run id in your script and see what it returns. check if the uid can
write to the directory you specify.
run pwd in the script to see where the default dir is.
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 7 Feb 1999 01:56:38 GMT

Neo Yong Teck <neoyongt@cisacsg.iscs.nus.sg> wrote:
->can tell me what's uid and how do i run id in my script ? thks.

The following script should do it:

#!/usr/bin/perl
use CGI qw/:standard/;
print header(), start_html('who am i?'), 
print 'I AM:', `whoami`, 'staying in ', `pwd`;
print end_html();

From: JnZ <jouweihu@comp.nus.edu.sg>
Subject: [javascript] how do i?
Date: 6 Feb 1999 03:57:56 GMT

Using javascript, I know I can open a new window with no
toolbar,statusline etc.

Is there anyway for a javascript-enabled webapge to change itself to
toolbarless etc.?
From: Wu Yinghui <wuyinghu@comp.nus.edu.sg>
Date: 8 Feb 1999 03:16:49 GMT

there is a method in window object in js

open( "URL", "name", "specs" ) 

u can actually use the "specs" argument to specify the appearance of the newly created window:
height = ####
width = ####
toolbar = true | false
status = true | false
menubar = true | false
scollbars = true | false
resizable = true | false
copyhistory= true | false

For Netscape 4, u can use even more attributes:

alwaysLowered, alwaysRaised, dependent, hotkeys, innerHeight, innerWidth,
outerHeight, outerWidth, screenX, screenY, titlebar, z-lock

So, maybe u can try out these properties to specify the appearance of the new window. 

> Is there anyway for a javascript-enabled webapge to change itself to
> toolbarless etc.?

i think this may be a bit more difficult since browsers have their own security control that u r allowed to control only

the windows created by urself.