Yes, I think you are being too pedantic. Use strict, but not prototypes.

For me, the value of "strict" is that it prevents me from accidentally
auto-vivifying misspelled variable names. Thinking you said $foo = 5, when
you really said $foe = 5, will introduce insidious bugs that are hard to
find.

For subroutines, I always use the "&" to denote a subroutine call, i.e.
&foo; No prototypes needed. I've grown accustomed to seeing &sub, just like
I'm accustomed to seeing $scalar, @list, and %hash. Also, recursion works
with no complaints.

cn

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steve
Dawson
Sent: Friday, September 16, 2005 7:00 AM
To: [email protected]
Subject: does anyone use prototypes

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
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to