Brian wrote:
This is what I'm using upto the code that is giving me a headache.
I know it's messy, but I have no training in PERL, I am trying to
forward-engineer this cgi by back-engineering from html templates I
created and which were chosen using $t->src
thanks for any help
Brian
#! c:\perl\bin\perl.exe -T
use warnings;
#use strict;
You should not disable strict, it can help you find mistakes.
use CGI qw/:all/;
use CGI::Carp qw/fatalsToBrowser/;
use HTMLTMPL;
my $t = HTMLTMPL->new();
my $q = new CGI;
my $val1 = $q->param('language');
my $val2 = $q->param('year');
#my $submit = $q->param('Submit');
chomp($Lang = $val1);
chomp($Year_in = $val2);
chomp() removes the contents of the $/ variable from the end of the
string. What makes you think that $val1 and $val2 need to be chomp()ed?
my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ];
my $today = $year + 1900;
################ set default language
if ($Lang eq '' ) {$Lang = en;}
Strings need to be quoted, either 'en' or "en". This is a requirement
of most, if not all, programming languages.
################ handle the strings
{
$string1 = aaaaaaaaaaabbbbbbbbbbbbbb;
$string2 = cccccccccccdddddddddddddd;
$string3 = eeeeeeeeeeeffffffffffffff;
$string4 = ggggggggggghhhhhhhhhhhhhh;
Again, you must quote your strings.
if ($Year_in <= 0 ) {$Year_in = $today;}
$Year_out = $Year_in;
while ($Year_out > 100) {$Year_out -= 100;}
No need for a loop
( $Year_out %= 100 ) ||= 100;
if (($Year_out > 00) && ($Year_out <= 25)) {$string = $string1;}
if (($Year_out > 25) && ($Year_out <= 50)) {$Year_out -=
100;$string = $string2;}
if (($Year_out > 50) && ($Year_out <= 75)) {$Year_out -=
200;$string = $string3;}
if (($Year_out > 75) && ($Year_out <= 100)) {$Year_out -=
300;$string = $string4;}
$Calend = substr $string, $Year_out-1, 1;
my @strings = (
( 'a' ) x 11,
( 'b' ) x 14,
( 'c' ) x 11,
( 'd' ) x 14,
( 'e' ) x 11,
( 'f' ) x 14,
( 'g' ) x 11,
( 'h' ) x 14,
);
if ( $Year_out > 0 && $Year_out <= 100 ) {
$Calend = $strings[ $Year_out - 1 ];
$Year_out -= int( ( $Year_out - 1 ) / 25 ) * 100;
}
}
################ user selected language
if ($Lang eq en)
Again, you must quote your strings.
{
($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec)
=
("January","February","March","April","May","June","July","August","September","October","November","December");
}
[ *SNIP* ]
# $i actually required to be greater than a 10 count, but if I can get
# the 2 blocks below to work, I will be able to play about with
# the code and increase it to the desired level.
#################################################################
for ( $i <=10; $i += 1 ; ) {
The for loop synax is:
for ( STATEMENT; CONDITIONAL; STATEMENT ) {
So "$i <=10" is superfluous and "$i += 1" is always true if $i is true
so it will loop until $i becomes 0 which can only happen if $i starts
out as a negative number.
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/