Prev: Does this match any number or just single digit ones?
Next: FAQ 6.24 How do I match a regular expression that's in a variable?
From: HerbF on 6 Aug 2010 16:49 I typically call subroutines without using parenthesis, e.g., &abc;. I have one routine where I pass variables and I call it as: &abc(A,B,C);: sub abc { $A = $_[0]; B=$_[1]; C=$_[2]; } Should I be using parenthesis at the subroutine, i.e., sub abc (A,B,C) {...} and why? TIA, Herb
From: Uri Guttman on 6 Aug 2010 16:55 >>>>> "H" == HerbF <HerbF(a)earthlink.net> writes: H> I typically call subroutines without using parenthesis, e.g., &abc;. I H> have one routine where I pass variables and I call it as: that is poor perl code and perl4 style. don't use & for sub calls as it has side effects you may not know about. read perldoc perlsub for more. H> Should I be using parenthesis at the subroutine, i.e., H> sub abc (A,B,C) {...} that has nothing to do with parens at the sub call itself. perl doesn't support named arguments like you have there so it won't do any good to try it. sub calls should be made with parens is the common style rule and not with &. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: HerbF on 6 Aug 2010 17:01 Uri Guttman wrote: >>>>>> "H" == HerbF <HerbF(a)earthlink.net> writes: > > H> I typically call subroutines without using parenthesis, e.g., &abc;. I > H> have one routine where I pass variables and I call it as: > >that is poor perl code and perl4 style. don't use & for sub calls as it >has side effects you may not know about. read perldoc perlsub for more. > > H> Should I be using parenthesis at the subroutine, i.e., > > H> sub abc (A,B,C) {...} > >that has nothing to do with parens at the sub call itself. perl doesn't >support named arguments like you have there so it won't do any good to >try it. > >sub calls should be made with parens is the common style rule and not >with &. > Thanks. Do I understand you to say that &abc; is "wrong" and that I should be using abc(); instead? As I'm calling one routine as &abc(A,B,C); what is the correct syntax? Herb
From: Uri Guttman on 6 Aug 2010 17:17 >>>>> "H" == HerbF <HerbF(a)earthlink.net> writes: >> sub calls should be made with parens is the common style rule and not >> with &. H> Thanks. Do I understand you to say that &abc; is "wrong" and that I H> should be using abc(); instead? yes. i just said that. so do the docs. please read them as that is the best way to learn perl. there is a whole doc just for perl subs. H> As I'm calling one routine as &abc(A,B,C); what is the correct syntax? no, drop the & as it is NOT NEEDED nor desirable. it marks your coding style as ancient perl4ish. it can cause issues you don't know about. parens are all you need and are correct. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Tad McClellan on 6 Aug 2010 17:28
HerbF(a)earthlink.net <HerbF(a)earthlink.net> wrote: > Uri Guttman wrote: > >>>>>>> "H" == HerbF <HerbF(a)earthlink.net> writes: >> >> H> I typically call subroutines without using parenthesis, e.g., &abc;. I >> H> have one routine where I pass variables and I call it as: >> >>that is poor perl code and perl4 style. don't use & for sub calls as it >>has side effects you may not know about. read perldoc perlsub for more. >> >> H> Should I be using parenthesis at the subroutine, i.e., >> >> H> sub abc (A,B,C) {...} >> >>that has nothing to do with parens at the sub call itself. perl doesn't >>support named arguments like you have there so it won't do any good to >>try it. What you have there is called a "prototype", they are often a Bad Idea, so you shouldn't be using them at all. If what you want is named arguments, then you typically do that by copying the args in the first statement in the subroutine body: sub abc { my($A, $B, $C) = @_; ... But don't choose one-letter variable names! >>sub calls should be made with parens is the common style rule and not >>with &. >> > Thanks. Do I understand you to say that &abc; is "wrong" and that I should > be using abc(); instead? Yes. > As I'm calling one routine as &abc(A,B,C); what is the correct syntax? abc(A,B,C); perldoc -q difference What's the difference between calling a function as &foo and foo()? -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site. |