John W. Krahn wrote:
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
#! c:\perl\bin\perl.exe -T
use warnings;
#use strict;
You should not disable strict, it can help you find mistakes.
But it works with strict turned off.
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?
Oops, they are leftovers from when I was using STDIN
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;
As I wasn't expecting help at this point, I replaced the strings true data.
I was of the understanding that PERL could handle a string of any
length, when I originally tried to use a string of 400 chars the prog
would refuse, so I changed it to 4 strings of 100 chars.
I would love to be able to be able to use a single string, but as this
method works, I am stuck with it.
I still need to use
$Calend = substr $string, $Year_out-1, 1;
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;
}
################ 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.
I have 2 books, 1 is the Camel book of PERL, the other is SAMS teach
yourself cgi in 24 hours. About £20 each.
In SAMS, the only reference to code for counting is as follows
$i = 0;
while ($i < 100) {
$i++;
}
with the following text
"This loop doesn't actually do anything, it just increments $i every
time the loop is executed and exits when $i gets to 99."
And the PERL book isn't any more helpful.
Teach yourself in 24 hrs?
I have spent the last 72 hrs trying to work out how to test to see if
$i = 1 and $mystart < 1
$i = 1 and $mystart > 0
$i = 2..10 and $mystart = < 1
Si = 2..10 and $mystart = > 0
and print according to the result.
and I still can't do it.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/