home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7416 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  1.6 KB

  1. Path: sparky!uunet!olivea!sgigate!sgi!wdl1!wdl39!mab
  2. From: mab@wdl39.wdl.loral.com (Mark A Biggar)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Is this a bug...
  5. Message-ID: <1992Dec14.192957.7730@wdl.loral.com>
  6. Date: 14 Dec 92 19:29:57 GMT
  7. References: <1gi84dINNhcv@armory.centerline.com>
  8. Sender: news@wdl.loral.com
  9. Organization: Loral Western Development Labs
  10. Lines: 35
  11.  
  12. In article <1gi84dINNhcv@armory.centerline.com> thomaso@centerline.com (Thomas Andrews) writes:
  13. >It appears that calling a subroutine with no argument list is not the
  14. >same as calling the subroutine with an empty argument list.  That is,
  15. >    &foo();
  16. >is different from
  17. >    &foo;
  18. >I could not find documentation for this in the camel book.  Is this
  19. >a bug or a feature?
  20. >In particular, the following prints out "Just another Perl hacker,":
  21. >sub func {
  22. >    print join(" ",@_),"\n";
  23. >}
  24. >sub main {
  25. >    &func;
  26. >}
  27. >&main("Just","another","Perl","hacker,");
  28. >while if main were defined as:
  29. > sub main {
  30. >    &func();
  31. > }
  32. >It would print a blank line...
  33.  
  34. This behavior is implied by the explaination in Para 5 of the section on 'do'
  35. Page 138 of the camel book.  It says "If you omit the parentheses, no @_
  36. array is passed to the subroutine."  Given how the dynamic scoping of perl
  37. variables works, if no @_ is passed to a subroutine, any references to @_
  38. in the subroutine must be to the @_ currently in the dynamic scope of the 
  39. subroutine which is usually the @_ of the calling routine.  Larry and I have
  40. discussed making the @_ of a subroutine one of the new lexical variables, but
  41. that would break any script dependent on the current dynamic scoping behavior.
  42.  
  43. --
  44. Perl's Maternal Uncle
  45. Mark Biggar
  46. mab@wdl1.wdl.loral.com
  47.