-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, Perhaps this is not the place for the HelloWorld.pl. I'll be quick. On Thu, 16 Mar 2000 22:25:15 -0800, SJ Black wrote:
Here is a script i was given to run a roman numeral webpage counter. I'm not a perl-er, so i don't know if it *should* be able to work in its current state, and if so, i'd so love to be able to make it do so.
It should work. But you may consider this points: - - Which working directory are you using. - - Which parameters is using your CGI call. - - Create for first time the counter file or change the script to create counters from scratch. - - The script needs to be executable (man chmod). - - Your working directory must be mapped into your cg-bin URL. Now let's take a look at the code: #!/usr/local/bin/perl # This first line is the invocation of PERL interpreter # This variable is used to store the working directory of your application # Make sure this is your working directory $directory = '/usr/local/httpd/cgi-bin'; # This first line opens standard output and prints out a MIME header # When it is call from your WEB server, the stdout is your output stream # to the server. So this line outputs back to the user a MIME header to # notice that a plain HTML page is coming. print "Content-Type: text/html\n\n"; # Here is where you use your $directory unless (chdir($directory)) { die "<BR>chdir($directory) failed - $!<BR>\n"; } # Checks if there's an enviroment variable. # Probably this data is passed in the CGI call inside a hidden value # The DOCUMENT_URI is used to name your counter file. unless ($ENV{'DOCUMENT_URI'}) { print "<BR>Document variable not supported.<BR>\n"; exit; } $Document = $ENV{'DOCUMENT_URI'}; # Strips any slash from the file name. $Document =~ s/\//_/g; # Opens the counter file for reading. This is a possible point to stop. # When starting for first time a counter the file doesn't exist. # You must create the file in advance... Or introduce some new changes. # open (COUNT, "<$Document") || create the file... if (open(COUNT,"<$Document")) { $Hits = <COUNT>; close(COUNT); } # This is the main functionality! $Hits++; # Opens file for writing the new value. if (open(COUNT,">$Document")) { print COUNT $Hits; close(COUNT); } else { print "<!-- could not write to $Document, $! -->\n"; } # Here you take the cardinal number in $Hits and split it in characters # The order is reversed and each character is put into the $Ones, $Tens... ($Ones,$Tens,$Hundreds) = split(//, reverse $Hits); print 'M' x int($Hits/1000); # Then prints a value from the array using $unit as the index print (('','C','CC','CCC','CD','D','DC','DCC','DCCC','CM')[$Hundreds]); print (('','X','XX','XXX','XL','L','LX','LXX','LXXX','XC')[$Tens]); print (('','I','II','III','IV','V','VI','VII','VIII','IX')[$Ones]); I suggest you to take a look at PERLREF and try to rewrite a clever routine to manage the file. Just open all in once in read/write mode, don't open twice... And if you can not find the file just write a new file starting with zero. Welcome to poetry world of PERL ;-) Pep Serrano pep@serrano.net http://pep.serrano.net -----BEGIN PGP SIGNATURE----- Version: PGPsdk version 1.7.1 (C) 1997-1999 Network Associates, Inc. and its affiliated companies. iQA/AwUBONLHisXRH5QDajQrEQJCeQCeOmF+eoKVC2NoH/GD7B8muQNAoNoAoMCm PA0USlTmrdR77eEVYkKLg0Lz =sDbp -----END PGP SIGNATURE----- -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/