in reply to home work help

One major problem is that you tend to forget the dollar sign before your variables. Take this line, for example:
elsif (x = max - 1)
You should probably add this line near the top, and then declare your variables with my:
use strict;
It will help you catch these kinds of errors.

Update: I believe that if() statements and for() loops require curly braces, even if they are one-liners. Code such as this:

for (...) if (...) ...blah...
should be like this:
for (...) { if (...) { ...blah... } }
buckaduck

Replies are listed 'Best First'.
Re: Re: home work help
by mbond (Beadle) on Jun 20, 2001 at 18:04 UTC
    Another way to handle one-liners would be to simply have the If statment afterwards
    print "foo \n" if $bar > 3;
    and for short things, this also works ... I like it to help keep the scrolling/line count down.
    for(my $I=0;$I<10;$I++) { print "foo \n" if $bar > 10 }
    I leave the semi-colon off for one line loops, just for readability sake, but include it on multiline loops. Strict doesn't yell about it, and its just a personal style thing.

    mbond
    A reply falls below the community's threshold of quality. You may see it by logging in.