Re: stuck in a control loop
am 24.10.2007 09:05:54 von Keith Keller
On 2007-11-24, Wade Ward wrote:
> # $m
> my $number13 = 42;
> my $number14 = 42;
>
>
> while ($notdone)
> {
[loop snipped]
> }
>
> Why do numbers 13 and 14 not print?
Your loop is never executed, because $notdone is never true. I hope
you'll consider no longer making sweeping statements about Perl that are
demonstrably untrue in exchange for this advice. I also hope you'll
post code that compiles under use strict; in the future.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
Re: stuck in a control loop
am 31.10.2007 04:52:58 von merl the perl
"Keith Keller" wrote in message
news:if73v4xt7t.ln2@goaway.wombat.san-francisco.ca.us...
> On 2007-11-24, Wade Ward wrote:
>> # $m
>> my $number13 = 42;
>> my $number14 = 42;
>>
>>
>> while ($notdone)
>> {
>
> [loop snipped]
>
>> }
>>
>> Why do numbers 13 and 14 not print?
>
> Your loop is never executed, because $notdone is never true. I hope
> you'll consider no longer making sweeping statements about Perl that are
> demonstrably untrue in exchange for this advice. I also hope you'll
> post code that compiles under use strict; in the future.
>
> --keith
>
> --
> kkeller-usenet@wombat.san-francisco.ca.us
> (try just my userid to email me)
I'll do that, if you're hip.
## contract22.pl
## binary contraction in perl
## contributors: joe smith
use strict;
use warnings;
my $number1 = 42;
my $toploop1 = 2.71;
my $bottom1 = 2.71;
my $diff = 2.71;
my $power = 2;
my $base = .5;
my $comp = -.00057;
my $alpha1 = -.00057;
my $alpha2= -.00057;
my $avg = -.00057;
$power = $power - 1;
$comp = $base**$power;
print STDOUT "no 1 is $number1\n";
print STDOUT "power is $power\n";
print STDOUT "base is $base\n";
print STDOUT "comp is $comp\n";
print STDOUT "This is the top . e is, btw,$toploop1\n";
print STDOUT "This is the bottom. x, s.t. ln x is 1 is $bottom1\n";
print STDOUT "avg is $avg\n";
# end output prelims
my $cups_to_cc = 236.588238;
my $cent_to_inch = 0.393700787;
my $no5 = 3;
my $no6 = 4**$no5;
my $no7 = $cups_to_cc * ($cent_to_inch**$no5);
my $no8 = 2**$no7;
my $no9 = 10*$no8;
my $no10 = 7.35;
my $no11 = .03;
print STDOUT "This is the bottom. x, s.t. ln x is 1 is $bottom1\n";
my $lower = $no10 + $no11;
my $upper= $no10 - $no11;
my $notdone1 = 1;
my $notdone2 = 1;
my $temp= 42.1;
my $exp = 1;
my $epsilon = 2**(-1*$exp);
my $number13 = 42;
my $number14 = 42;
$avg = ($upper + $lower) / 2.0;
print STDOUT "avg is $avg\n";
#end prelims
while ($notdone1)
{
if ($upper <= $lower)
{
$temp = $upper;
$upper = $lower;
$lower = $temp;
}
$notdone1 = $notdone1 - 1;
# end notdone while loop
###########
print STDOUT "You're ########### here. $bottom1\n";
if ($diff < $comp)
{
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
}
print STDOUT "You're ########### here. $bottom1\n";
###########
}
# At this point, upper is guaranteed to be greater/= than lower
#####
### main control
###########
print STDOUT "You're ##*********. $bottom1\n";
if ($diff < $comp)
{
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
}
print STDOUT "You're ##******** here. $bottom1\n";
###########
print STDOUT "begin is $number13\n";
$diff = $upper - $lower;
while ($notdone2)
{
print STDOUT "begin is $number13\n";
print STDOUT "comp is $comp\n";
if (($diff > $comp) or ($power = 6))
{
###########
print STDOUT "You're &&&&&******. $bottom1\n";
if ($diff < $comp)
{
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
}
print STDOUT "You're #&&&* here. $bottom1\n";
###########
print STDOUT "This is the top . e is, btw,$toploop1\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "power is $power\n";
}
else
{
$avg = ($upper + $lower) / 2.0;
$alpha1 = $upper - $avg;
$alpha2 = $lower + $avg;
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
### get the smaller of the alpha's
if ($alpha2 > $alpha1)
{
$alpha2 = $alpha1;
}
### alpha2 is smaller
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
$upper = $avg + $alpha2;
$lower = $avg - $alpha2;
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
$power = $power + 1;
print STDOUT "power is $power\n";
###########
print STDOUT "You're ##*********. $bottom1\n";
if ($diff < $comp)
{
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
}
print STDOUT "You're ##******** here. $bottom1\n";
###########
# end else clause
}
print STDOUT "You're just south of the else here. $bottom1\n";
## print all vars
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "upper is $upper\n";
print STDOUT "lower is $lower\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
print STDOUT "comp is $comp\n";
print STDOUT "avg is $avg\n";
#####
print STDOUT "end is $number14\n";
$notdone2 = $notdone2 - 1;
# end $notdone2 while loop
}
print STDOUT "You're just south of the notdone2 loop. $bottom1\n";
### end main control
print STDOUT "end is $number14\n";
### output
print STDOUT "avg is $avg\n";
print STDOUT "alpha1 is $alpha1\n";
print STDOUT "alpha2 is $alpha2\n";
print STDOUT "lower is $lower\n";
print STDOUT "upper is $upper\n";
print STDOUT "diff is $diff\n";
# perl contract21.pl
# perl contract19.pl 2>text55.txt >text56.txt
__END__
Why is perl different from its muttersprache as it regards what can be
modified in a loop?
> you'll consider no longer making sweeping statements about Perl that are
> demonstrably untrue in exchange for this advice. I also hope you'll
> post code that compiles under use strict; in the future.
My sweeping, wrong statements come from a learner. Adjust accordingly.
> post code that compiles under use strict; in the future
You have semi-colon fatigue. Take a look at fortran.
--
mpj
tja
and