I hear everybody constantly chanting the use strict and use warnings mantra in this and every other perl group. No argument there, but what's the position on prototypes in subs? I prefer to use them but that's probably because I was taught Pascal way back when and now I compulsively want to type all my variables and predeclare my subroutines, unlike my C trained workmates who put their main() at the top of the code.

One nagging thing with prototypes is when I use them recursively warnings carps about not being able to test the prototype so I end up wrapping it in a no warnings (example below). Am I being too pedantic about my subs and should I just trust myself not to call the subs incorrectly?

Steve

sub descend($$){ #map out the endpoints of an unknown record structure my ($name,$ref) = @_; #accumulated name of var and scalar or ref to the next level if(ref($ref) eq ''){ #map scalar endpoints print $name.": [$ref]\n"; } if(ref($ref) eq 'HASH'){ #explore the keys of a hash
       print "$name: [undef]\n" unless(scalar(keys %$ref));
       for my $element (keys %$ref){
no warnings; #disable warning for recursion
           descend($name.".$element",$ref->{$element});
       }
   }
if(ref($ref) eq 'ARRAY'){ #enumerate the elements of an array
       print "$name: [undef]\n" unless(scalar(@$ref));
       my $index = 0;
       for my $element (@$ref){
no warnings; #disable warning for recursion
           descend($name.".[$index]",$element);
           $index ++;
       }
   }
}


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to