[ic] recursive perl subroutine

marc.brevoort interchange-users@icdevgroup.org
Wed Sep 4 04:54:03 2002


On Tuesday 03 September 2002 18:27, you wrote:

> sub checktree {

>                          my ($catcode)=@_;
>                          if($catcode == 0)
>                          {
>                                  return 1;
>                          }

>                          elsif($catcode == $Variable->{WCODE})
Are $catcode and $Variable->{WCODE} numeric 
or text? You may want to try using eq instead of ==.
>                          {
>                                  return 0;
>                          }
>                          else
No need for 'else' here (or above), you're already jumping
out of the call.
>                          {
>                                  $db = $Db{cattable};

Where did you declare $db declared? 
If you are using it in a recursive call, most likely you want
to declare it as local variable by putting 'my $db' in the sub itself. 
Right now it seems to be declared outside it. 

Same goes for $parent, $row and $pcode.
>                                  $sql = "select pcode from cattable
> where pcode=".$catcode;
>                                  $parent = $db ->query({sql => "select
> pcode from cattable where code=".$catcode});
>                                  $row = shift (@$parent);
>                                  ($pcode) = @$row;
>                                  return checktree($pcode);
>                          }
> }
>
> is there something built into interchange to stop recursive calls? 
No :)

> is there a syntax error in my code
If there is, error.log should show it.

Hope this helps,

Regards,

Marc Brevoort