home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Newsgroups: comp.lang.perl
- Subject: Re: Is this a bug...
- Message-ID: <1992Dec14.192957.7730@wdl.loral.com>
- Date: 14 Dec 92 19:29:57 GMT
- References: <1gi84dINNhcv@armory.centerline.com>
- Sender: news@wdl.loral.com
- Organization: Loral Western Development Labs
- Lines: 35
-
- In article <1gi84dINNhcv@armory.centerline.com> thomaso@centerline.com (Thomas Andrews) writes:
- >It appears that calling a subroutine with no argument list is not the
- >same as calling the subroutine with an empty argument list. That is,
- > &foo();
- >is different from
- > &foo;
- >I could not find documentation for this in the camel book. Is this
- >a bug or a feature?
- >In particular, the following prints out "Just another Perl hacker,":
- >sub func {
- > print join(" ",@_),"\n";
- >}
- >sub main {
- > &func;
- >}
- >&main("Just","another","Perl","hacker,");
- >while if main were defined as:
- > sub main {
- > &func();
- > }
- >It would print a blank line...
-
- This behavior is implied by the explaination in Para 5 of the section on 'do'
- Page 138 of the camel book. It says "If you omit the parentheses, no @_
- array is passed to the subroutine." Given how the dynamic scoping of perl
- variables works, if no @_ is passed to a subroutine, any references to @_
- in the subroutine must be to the @_ currently in the dynamic scope of the
- subroutine which is usually the @_ of the calling routine. Larry and I have
- discussed making the @_ of a subroutine one of the new lexical variables, but
- that would break any script dependent on the current dynamic scoping behavior.
-
- --
- Perl's Maternal Uncle
- Mark Biggar
- mab@wdl1.wdl.loral.com
-