Re: help needed to get over endless loop

2009-04-20 Thread Brian

Thank you all for your much needed help.
The penny has managed to drop.

regards
Brian

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Chas. Owens
On Fri, Apr 17, 2009 at 21:35, Brian  wrote:
snip
> LOL, I didn't understand any of that. :-)
> Apart from the last sentence ;-)
snip

Think of a clock, they hands can go around as many times as you like
but they can never point to anything higher than 12.  Modulus works
the same way, the second value acts as a cap:

0 % 4 = 0
1 % 4 = 1
2 % 4 = 2
3 % 4 = 3
4 % 4 = 0
5 % 4 = 1
6 % 4 = 2
7 % 4 = 3
8 % 4 = 0

It is really the remainder of the division: 7/4 = 1 plus a remainder of 3.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

John W. Krahn wrote:

Brian wrote:

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


[ *SNIP* ]



 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}


The usual way to calculate a leap year is:

sub is_leap_year {
my $year = shift;
return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0
}


I guess that % means 'wholly divisible by'


perldoc perlop

[ *SNIP* ]

Binary "%" computes the modulus of two numbers.  Given integer
operands $a and $b: If $b is positive, then "$a % $b" is $a minus
the largest multiple of $b that is not greater than $a.  If $b is
negative, then "$a % $b" is $a minus the smallest multiple of $b
that is not less than $a (i.e. the result will be less than or equal
to zero).  Note that when "use integer" is in scope, "%" gives you
direct access to the modulus operator as implemented by your C
compiler.  This operator is not as well defined for negative
operands, but it will execute faster.

LOL, I didn't understand any of that. :-)
Apart from the last sentence ;-)




And presumably starts out as a 4 digit number, gets tested and 
overwritten by 0 or 1, 1 being true?


What starts out as a 4 digit number?  What gets tested?  What gets 

$year
overwritten?  You will have to be more specific on what you think is 
happening for me to either agree with you or correct you.



I'm tired, it's about 5 hours past my bedtime.
I think I had better go hit the sack.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread John W. Krahn

Brian wrote:

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


[ *SNIP* ]



 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}


The usual way to calculate a leap year is:

sub is_leap_year {
my $year = shift;
return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0
}


I guess that % means 'wholly divisible by'


perldoc perlop

[ *SNIP* ]

Binary "%" computes the modulus of two numbers.  Given integer
operands $a and $b: If $b is positive, then "$a % $b" is $a minus
the largest multiple of $b that is not greater than $a.  If $b is
negative, then "$a % $b" is $a minus the smallest multiple of $b
that is not less than $a (i.e. the result will be less than or equal
to zero).  Note that when "use integer" is in scope, "%" gives you
direct access to the modulus operator as implemented by your C
compiler.  This operator is not as well defined for negative
operands, but it will execute faster.


And presumably starts out as a 4 digit number, gets tested and 
overwritten by 0 or 1, 1 being true?


What starts out as a 4 digit number?  What gets tested?  What gets 
overwritten?  You will have to be more specific on what you think is 
happening for me to either agree with you or correct you.




 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}


use Time::Local;

sub year_starts_sunday {
my $year = shift;
return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ]
}



Oh oh oh, I think you think I am only working with the current year.


No, I do not think that.  However using timegm() implies a certain upper 
and lower bound to the range of years that can correctly be calculated.




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/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

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


[ *SNIP* ]



 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}


The usual way to calculate a leap year is:

sub is_leap_year {
my $year = shift;
return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0
}


I guess that % means 'wholly divisible by'
And presumably starts out as a 4 digit number, gets tested and 
overwritten by 0 or 1, 1 being true?







 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}


use Time::Local;

sub year_starts_sunday {
my $year = shift;
return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ]
}



Oh oh oh, I think you think I am only working with the current year.
This is how my live prog works using "cgi loading templates"
http://www.absey-vine.co.uk/calendar/

and this is how my "cgi only" runs, it only displays 2006 regardless of 
the year you input.

http://www.absey-vine.co.uk/calendar/testing123/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

Brian wrote:

John W. Krahn wrote:

Brian wrote:


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



Actually, I have just tried to remove the chomps and the program stops 
working properly.

So it looks like they will have to stay put for a while.

:-(

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

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 = aaabb;
$string2 = cccdd;
$string3 = eeeff;
$string4 = ggghh;


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/




Re: help needed to get over endless loop

2009-04-17 Thread John W. Krahn

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


[ *SNIP* ]



 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}


The usual way to calculate a leap year is:

sub is_leap_year {
my $year = shift;
return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0
}



 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}


use Time::Local;

sub year_starts_sunday {
my $year = shift;
return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ]
}




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/




Re: help needed to get over endless loop

2009-04-17 Thread John W. Krahn

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 = aaabb;
$string2 = cccdd;
$string3 = eeeff;
$string4 = ggghh;


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/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

Jim Gibson wrote:

On 4/17/09 Fri  Apr 17, 2009  1:50 PM, "Brian" 
scribbled:


Brian wrote:

oops, should read..

  $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 -=
  25;$string = $string2;}
  if (($Year_out > 50) && ($Year_out <= 75)) {$Year_out -=
  50;$string = $string3;}
  if (($Year_out > 75) && ($Year_out <= 100)) {$Year_out -=
  75;$string = $string4;}


You are doing quite a few redundant tests here. Note that after your while
loop, $Year_out cannot be greater than 100. Also, if $Year_out is greater
than 25, it must be greater than 0. In addition, when you are done,
$Year_out will be between 0 and 25. Therefore, you can take the value modulo
25 and rearrange the tests to be a little more efficient (I am assuming that
$Year_out is always >= zero):

while ( $Year_out > 100 ) {
$Year_out -= 100;
}
if ( $Year_out > 75 ) {
$string = $string4;
}elsif ( $Year_out > 50 {
$string = $string3;
}elsif ( $Year_out > 25 ) {
$string = $string2;
}elsif ( $Year_out > 0 ) {
$string = $string1;
}
$Year_out = $Year_out % 25;





Thanks for that, a better structure, but I don't understand the use of % 
25 in this instance.
$year is actually always going to be >= zero , even if someone enters a 
negative.
I haven't factored for the Julian/Gregorian changeover, so this prog 
will calc year 1 as it would have been had todays calendar been in use 
2000+ years ago.
A point I should make here is that I am actually working over 400 year 
cycles and not 100, so...

100 = 400
75  = 300
50  = 200
25  = 100
but I suppose the results will be this same in your code above.
(I changed certain parameters to stop any robots from stealing my code)
;-)


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Jim Gibson
On 4/17/09 Fri  Apr 17, 2009  1:50 PM, "Brian" 
scribbled:

> Brian wrote:
> 
> oops, should read..
> 
>   $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 -=
>   25;$string = $string2;}
>   if (($Year_out > 50) && ($Year_out <= 75)) {$Year_out -=
>   50;$string = $string3;}
>   if (($Year_out > 75) && ($Year_out <= 100)) {$Year_out -=
>   75;$string = $string4;}

You are doing quite a few redundant tests here. Note that after your while
loop, $Year_out cannot be greater than 100. Also, if $Year_out is greater
than 25, it must be greater than 0. In addition, when you are done,
$Year_out will be between 0 and 25. Therefore, you can take the value modulo
25 and rearrange the tests to be a little more efficient (I am assuming that
$Year_out is always >= zero):

while ( $Year_out > 100 ) {
$Year_out -= 100;
}
if ( $Year_out > 75 ) {
$string = $string4;
}elsif ( $Year_out > 50 {
$string = $string3;
}elsif ( $Year_out > 25 ) {
$string = $string2;
}elsif ( $Year_out > 0 ) {
$string = $string1;
}
$Year_out = $Year_out % 25;



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

Kevin Ponds wrote:

Brian,

Your while loops aren't actually performing any operation on the variable


I did actually state that the loops wouldn't work.

I adjusted them to better show what I want to achieve, not to show how I 
am trying to achieve it.



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.


I've tried using while, if and for in different ways, whilst some 
permutations worked partially, I haven't been able to figure out the 
correct way of laying the code out to do a couple of basic tests.
I'm going back and forth on something that looks to me like it should be 
so damned simple to figure out.




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.


Yes I agree, but whilst I am at a point where I am having trouble 
working out one simple step, I really don't think it a good idea to 
break it into loads of subroutines.
I get confused easily, as can be seen by my inability to solve the 
problem below.




On Fri, Apr 17, 2009 at 3:46 PM, Brian  wrote:



for ( $i <=10; $i += 1 ; ) {

while ($i == 1 ) {

   if  ($mystart < 1 ) {
   print "
   "
}

   if  ($mystart > 0 ) {
   print "
   $mystart"
}
}
}
while ($i == 2..10 ) {

while ($i > 1 ) {

   if  ($mystart < 1 ) {
   print "
   "
}

   if  ($mystart > 0 ) {
   print "
   $mystart"
}
}
}
#}




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Kevin Ponds
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  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 = aaabb;
> $string2 = cccdd;
> $string3 = eeeff;
> $string4 = ggghh;
>
> 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 );
>
>
>
>
>
> ##

Re: help needed to get over endless loop

2009-04-17 Thread Brian

Brian wrote:

oops, should read..

 $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 -=
 25;$string = $string2;}
 if (($Year_out > 50) && ($Year_out <= 75)) {$Year_out -=
 50;$string = $string3;}
 if (($Year_out > 75) && ($Year_out <= 100)) {$Year_out -=
 75;$string = $string4;}


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Brian

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 = aaabb;
$string2 = cccdd;
$string3 = eeeff;
$string4 = ggghh;

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 "

\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">



$Year_in<\/title>

Re: help needed to get over endless loop

2009-04-17 Thread Brian

Wagner, David --- Senior Programmer Analyst --- CFS wrote:

-Original Message-
From: Brian [mailto:brian5432...@yahoo.co.uk] 
Sent: Friday, April 17, 2009 11:03

To: Perl Beginners
Subject: help needed to get over endless loop

Hi
I had this semi-working, changed something and can't remember where I 
went right, so would appreciate some help getting back on top.


I know 1..10 and 2..10 probably won't work in the following 
example, I 
have just changed lines to show what I am trying to get.




You are not running with strict, warnings which would give you a
heads up

$mystart = -2;
$i = 1;

for ($i = 1..10 ) {

while ($i = 1 ) {

You would get warning if warnings were on. You are assigning 1
to $i and not $i == 1.
Better to give your code for the list to review.



I pretty much scrapped everything I had and have used the code as posted 
as a new starting point, therefore that is all I am working with at the 
moment.

if I use strict I get a couple of screenfuls of warnings, mostly
Global symbol "$xxx" requires explicit package name at 
and a few Bareword warnings, but they seem to be because of
"strict subs" in use

If I can answer both you and Jim here...

I want to count from 1 to 10, I assigned $i as 1 so as not to need to 
test $i against negative.
However, at the count of 1, I check to see if $mystart is positive or 
negative.

If it is neg, a null value is printed.
If it is pos, $mystart is printed in red.

From count 2 thru 10...
If it is neg, a null value is printed.
If it is pos, $mystart is printed in black.

I need to retain the value of $i as this block of code will be re-used 
further into the cgi.



regards
Brian

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: help needed to get over endless loop

2009-04-17 Thread Wagner, David --- Senior Programmer Analyst --- CFS

> -Original Message-
> From: Brian [mailto:brian5432...@yahoo.co.uk] 
> Sent: Friday, April 17, 2009 11:03
> To: Perl Beginners
> Subject: help needed to get over endless loop
> 
> Hi
> I had this semi-working, changed something and can't remember where I 
> went right, so would appreciate some help getting back on top.
> 
> I know 1..10 and 2..10 probably won't work in the following 
> example, I 
> have just changed lines to show what I am trying to get.
> 

You are not running with strict, warnings which would give you a
heads up
> $mystart = -2;
> $i = 1;
> 
> for ($i = 1..10 ) {
> 
> while ($i = 1 ) {
You would get warning if warnings were on. You are assigning 1
to $i and not $i == 1.
Better to give your code for the list to review.

 If you have any questions and/or problems, please let me know.
 Thanks.
 
Wags ;)
David R. Wagner
Senior Programmer Analyst
FedEx Freight
1.719.484.2097 TEL
1.719.484.2419 FAX
1.408.623.5963 Cell
http://fedex.com/us 


>   if  ($mystart < 1 ) {print "line 1 no data"}
>   if  ($mystart > 0 ) {print "line 1 data"}
>   $mystart++ ; $i++;
> }
> }
> 
> 
> 
> while ($i = 2..10 ) {
>   if  ($mystart < 1 ) {print "line 2..10 no data"}
>   if  ($mystart > 0 ) {print "line 2..10 with data"}
>   $mystart++ ; $i++;
> }
> }
> 
> 
> thanks
> Brian
> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help needed to get over endless loop

2009-04-17 Thread Jim Gibson
On 4/17/09 Fri  Apr 17, 2009  10:02 AM, "Brian" 
scribbled:

> Hi
> I had this semi-working, changed something and can't remember where I
> went right, so would appreciate some help getting back on top.
> 
> I know 1..10 and 2..10 probably won't work in the following example, I
> have just changed lines to show what I am trying to get.
> 
> $mystart = -2;
> $i = 1;
> 
> for ($i = 1..10 ) {

for my $I ( 1..10 ) {

> 
> while ($i = 1 ) {

'=' is assignment, '==' is test for numerical equality. This loop will never
end, as $I gets assigned to the value 1 each time through the loop.

while( $i == 1 ) {

> if  ($mystart < 1 ) {print "line 1 no data"}
> if  ($mystart > 0 ) {print "line 1 data"}
> $mystart++ ; $i++;

You probably don't want to change $i inside a 'for my $I ( 1 .. 10 )' loop,
as the change will be overwritten at the next loop iteration. If you really
need to modify the loop iterator, then you should use a C-style for loop:

for( my $i = 0; $i <=10; $i++ ) {
...
}



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/