Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: subroutine inspecting its calling environment Message-ID: <100405@convex.convex.com> Date: 6 Mar 90 16:31:07 GMT References: <7283@jpl-devvax.JPL.NASA.GOV> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 39 In article <7283@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >In article jbw@bucsf.bu.edu (Joe Wells) writes: >: Some questions for the great perl gods: >: >: 1. Can a subroutine tell whether it was invoked without arguments? >: >: example: &subroutine_name; > >Not that I know of. Really? $#_ has always worked for me: #!/usr/bin/perl &callme; &callme('blue'); &callme(0); &callme(7,1); &callme(); exit 0; sub callme { local($count) = $#_ + 1; # assumes $[ == 0 printf "i was called with %s argument%s\n", $count, ($count == 1) ? '' : 's'; } Is there some reason this is not reliable? --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"