Brian,

Your while loops aren't actually performing any operation on the variable
that is being tested as part of their condition.  With while loops, if the
condition ($i in this case) is true at the start of the loop, and doesn't
change, they will loop forever.  They aren't like for loops, where you
pre-declare the increment operation that's ran every loop.  You need to add
some kind of code to increment the $i for each iteration of the loop such
that the condition eventually becomes false.  I'm not sure exactly what
logic you would use to do that, as I'm having a hard time figuring out what
these loops are supposed to do.

That being said, I think you would realize some benefit by stepping back and
looking at the overall design of your program, breaking it down into
subroutines and thinking about the clearest way to implement it.  I think
there are several ways to refactor this to make it much easier to write,
debug, and maintain.

On Fri, Apr 17, 2009 at 3:46 PM, Brian <brian5432...@yahoo.co.uk> 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;
>
>
> 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);
>
> my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ];
>        my $today = $year + 1900;
>
>
> ################ set default language
> if ($Lang eq '' ) {$Lang = en;}
>
> ################ handle the strings
> {
> $string1 = aaaaaaaaaaabbbbbbbbbbbbbb;
> $string2 = cccccccccccdddddddddddddd;
> $string3 = eeeeeeeeeeeffffffffffffff;
> $string4 = ggggggggggghhhhhhhhhhhhhh;
>
> if ($Year_in <= 0 ) {$Year_in = $today;}
>
> $Year_out = $Year_in;
>
>        while ($Year_out > 100) {$Year_out -= 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;
>
> }
>
> ################ user selected language
> if ($Lang eq en)
> {
> ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec)
> =
> ("January","February","March","April","May","June","July","August","September","October","November","December");
> }
> if ($Lang eq en)
> {
> ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day)
> = (
> "Sun","Mon","Tue","Wed","Thu","Fri","Sat");
> }
> if ($Lang eq fr)
> {
> ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec)
> =
> ("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Decembre");
> }
> if ($Lang eq fr)
> {
> ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day)
> = (
> "Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
> }
> if ($Lang eq de)
> {
> ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec)
> =
> ("Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
> }
> if ($Lang eq de)
> {
> ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day)
> = (
> "S","M","D","M","D","F","S");
> }
> if ($Lang eq ee)
> {
> ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec)
> =
> ("Jaanuar","Veebruar","Märts","Aprill","Mai","Juuni","Juuli","August","September","Oktoober","November","Detsember");
> }
> if ($Lang eq ee)
> {
> ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day)
> = (
> "P","E","T","K","N","R","L");
> }
>
>
> ################ whether or not leapyear
> {
> ($myleap = 0 )
> }
> if ($Calend eq "b" ) {$myleap += 1}
> if ($Calend eq "d" ) {$myleap += 1}
> if ($Calend eq "f" ) {$myleap += 1}
> if ($Calend eq "h" ) {$myleap += 1}
>
>
> ################ whether year starts on a Sunday
> {
> ($mystart = 0 )
> }
> if ($Calend eq "a" || $Calend eq "b") {$mystart -= 0}
> if ($Calend eq "c" || $Calend eq "d") {$mystart -= 1}
> if ($Calend eq "e" || $Calend eq "f") {$mystart -= 2}
> if ($Calend eq "g" || $Calend eq "h") {$mystart -= 3}
>
> ############## this prog originally written to choose a template
> ############## hence the following (superfluous) line
> #$t->src( "c:/apache2/htdocs/calendar/$Lang/$Calend.html" );
>
> $t->output( CGI::header );
>
>
>
>
>
> ################################################################################################################################
>
> ################################################################################################################################
>
> ################################################################################################################################
>
> ################################################################################################################################
>
>
>
> {
> print "
>
> <!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\"
> \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">
> <html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">
> <head>
> <title>$Year_in<\/title>
> <style type=\"text\/css\">
> <!--
> #Layer1 {
>        position:absolute;
>        left:39px;
>        top:36px;
>        width:132px;
>        height:167px;
>        z-index:1;
> }
> .style1 {color: #000000}
> .style4 {color: #FF3300; }
> body {
>        background-color: #003399;
> }
> .style5 {
>        font-size: 36px;
>        color: #FFFFFF;
> }
> .style6 {color: #FFFFFF}
> .style7 {color: #FF3300; font-size: 12px; }
> .style8 {font-size: 12px}
> .style9 {font-size: 24px}
> -->
> <\/style>
> <\/head>
> <body>
> $myjan
> $Calend
> $myleap
> $mystart
> <table width=\"10%\" height=\"287\" border=\"0\" align=\"left\"
> cellpadding=\"0\" cellspacing=\"0\">
>  <tr>
>    <td align=\"left\"><form action=\"http:\/\/localhost\/testing123\/\"
> method=\"get\" enctype=\"text\/plain\" name=\"year\" id=\"year\">
>      <p align=\"centre\" class=\"style1 style6\">
>        <label>"
> }
>
> if ($Lang eq en) { print "
>                  <input name=\"language\" type=\"radio\" value=\"en\"
> checked=\"checked\" \/>
>          <span class=\"style6\">English<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"fr\" \/>
>          <span class=\"style6\">French<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"de\" \/>
>          <span class=\"style6\">German<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"ee\" \/>
>          <span class=\"style6\">Estonian<\/span><\/label>
>                  <\/p>
>                  <p>
>          <label><span class=\"style6\">Pick a year:-<\/span>
>                  <input name=\"year\" type=\"text\" id=\"year\"
> value=\"$Year_in\" size=\"4\" \/>
>          <\/p>
>          <p>
>          <label>
>          <input name=\"Submit\" type=\"submit\" id=\"Submit\"
> value=\"Submit\" \/>
>          <\/label>
>      <\/p>
>    <\/form><\/td>
>  <\/tr>
> <\/table>"
> }
>
> if ($Lang eq fr) { print "
>                  <input name=\"language\" type=\"radio\" value=\"en\" \/>
>          <span class=\"style6\">Anglais<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"fr\"
> checked=\"checked\" \/>
>          <span class=\"style6\">Français<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"de\" \/>
>          <span class=\"style6\">Allemande<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"ee\" \/>
>          <span class=\"style6\">Estonien<\/span><\/label>
>                  <\/p>
>                  <p>
>          <label><span class=\"style6\">Choisissez une annee:-</<\/span>
>                  <input name=\"year\" type=\"text\" id=\"year\"
> value=\"$Year_in\" size=\"4\" \/>
>          <\/label>
>          <\/p>
>          <p>
>          <label>
>          <input name=\"Submit\" type=\"submit\" id=\"Submit\"
> value=\"Envoyer\" \/>
>          <\/label>
>      <\/p>
>    <\/form><\/td>
>  <\/tr>
> <\/table>"
> }
>
> if ($Lang eq de) { print "
>                  <input name=\"language\" type=\"radio\" value=\"en\" \/>
>          <span class=\"style6\">Englisch<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"fr\" \/>
>          <span class=\"style6\">Französisch<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"de\"
> checked=\"checked\" \/>
>          <span class=\"style6\">Deutsch<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"ee\" \/>
>          <span class=\"style6\">Estnisch<\/span><\/label>
>          <\/p>
>                  <p>
>          <label><span class=\"style6\">Wählen sie ein jahr:-</</<\/span>
>                  <input name=\"year\" type=\"text\" id=\"year\"
> value=\"$Year_in\" size=\"4\" \/>
>          <\/label>
>          <\/p>
>          <p>
>          <label>
>          <input name=\"Submit\" type=\"submit\" id=\"Submit\"
> value=\"Senden\" \/>
>          <\/label>
>      <\/p>
>    <\/form><\/td>
>  <\/tr>
> <\/table>"
> }
>
> if ($Lang eq ee) { print "
>                  <input name=\"language\" type=\"radio\" value=\"en\" \/>
>          <span class=\"style6\">Inglise keel<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"fr\" \/>
>          <span class=\"style6\">Prantsuse keel<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"de\" \/>
>          <span class=\"style6\">Saksa keel<\/span><\/label>
>                  <br \/>
>                  <label>
>                  <input name=\"language\" type=\"radio\" value=\"ee\"
> checked=\"checked\" \/>
>          <span class=\"style6\">Eesti keel<\/span><\/label>
>          <\/p>
>                  <p>
>          <label><span class=\"style6\">Vali aasta:-</</</<\/span>
>                  <input name=\"year\" type=\"text\" id=\"year\"
> value=\"$Year_in\" size=\"4\" \/>
>         <\/label>
>                  <\/p>
>          <p>
>          <label>
>          <input name=\"Submit\" type=\"submit\" id=\"Submit\"
> value=\"Saatma\" \/>
>          <\/label>
>      <\/p>
>    <\/form><\/td>
>  <\/tr>
> <\/table>"
> }
>
>
> {
> print "
> <table width=\"810\" align=\"center\" cellspacing=\"10\"
> bgcolor=\"#003399\">
>  <tr>
>    <td width=\"220\" bgcolor=\"#003399\"><table width=\"220\" border=\"0\"
> cellpadding=\"0\" cellspacing=\"0\">
>        <tr>"
> }
> {
> print "
> <th bgcolor=\"#FFFF33\" scope=\"col\">$myjan<\/th>
>        <\/tr>
>      <\/table>"
> }
>
>
> {
> print "
>        <table width=\"220\" border=\"1\" cellpadding=\"0\"
> cellspacing=\"0\" bordercolor=\"#999999\" bgcolor=\"#FFFFFF\">
>          <tr>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style7\">$mysun_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$mymon_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$mytue_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$mywed_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$mythu_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$myfri_day<\/div><\/th>
>        <th height=\"27\" scope=\"col\"><div align=\"center\"
> class=\"style8\">$mysat_day<\/div><\/th>
>            <\/tr>
>                        <tr>"
> }
> ########################## day table ############################
>
> #  $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 ; ) {
>
> while ($i == 1 ) {
>
>        if  ($mystart < 1 ) {
>                        print "
>                                <td width="27" height="27"><div
> align="center" class="style4"></div></td>"
> }
>
>        if  ($mystart > 0 ) {
>                        print "
>                                <td width="27" height="27"><div
> align="center" class="style4">$mystart</div></td>"
> }
> }
> }
> while ($i == 2..10 ) {
>
> while ($i > 1 ) {
>
>        if  ($mystart < 1 ) {
>                        print "
>                                <td width="27" height="27"><div
> align="center"></div></td>"
> }
>
>        if  ($mystart > 0 ) {
>                        print "
>                                <td width="27" height="27"><div
> align="center">$mystart</div></td>"
> }
> }
> }
> #}
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to