in reply to Re: Nested Conditional Statement Issue
in thread Nested Conditional Statement Issue

Two tips. First of all use strict. It catches a lot of simple typos (like the one that I suspect caused this question). Secondly in Perl if you see the chance, avoid C-style for loops for Perlish foreach loops whenever you can. Positional logic is notoriously easy to mess up with off by one, etc. For instance supposing that (base on another educated guess) that $cleng is the length of the array @course, this could be rewritten:
for (@class) { my ($id, $name, $credits) = split(/,/, $_); for my $course (@course) { $z++ if $course eq $id; } }
If that guess is wrong you could always just loop over the range 0..$cleng-1, or else 0..$cleng. (Although almost certainly my guess is right and you just want to loop over the @course array.)

And another tip to the original questioner. If you find yourself scanning arrays like this, that is usually a sign that you wanted to use a far more efficient hash lookup instead.

Replies are listed 'Best First'.
Re: Re (tilly) 2: Nested Conditional Statement Issue
by Anonymous Monk on May 07, 2001 at 03:09 UTC
    I'm going to try the use of a hash here if I can...that might just do the trick. Thanks