Path: utzoo!attcan!uunet!fernwood!decwrl!ucbvax!tut.cis.ohio-state.edu!mailrus!usenet.ins.cwru.edu!cwjcc!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery) Newsgroups: comp.lang.perl Subject: Re: subroutine inspecting its calling environment Message-ID: <1990Mar10.025904.25473@NCoast.ORG> Date: 10 Mar 90 02:59:04 GMT References: <7283@jpl-devvax.JPL.NASA.GOV> <100405@convex.convex.com> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery) Followup-To: comp.lang.perl Organization: North Coast Public Access UN*X, Cleveland, OH Lines: 25 As quoted from <100405@convex.convex.com> by tchrist@convex.COM (Tom Christiansen): +--------------- | 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: | >: 1. Can a subroutine tell whether it was invoked without arguments? | > | >Not that I know of. | | sub callme { | local($count) = $#_ + 1; # assumes $[ == 0 | printf "i was called with %s argument%s\n", | $count, ($count == 1) ? '' : 's'; | } +--------------- More portably, local($count) = $#_ - $[ + 1; Just another Perl diver, ;-) ++Brandon -- Brandon S. Allbery (human), allbery@NCoast.ORG (Inet), BALLBERY (MCI Mail) ALLBERY (Delphi), uunet!cwjcc.cwru.edu!ncoast!allbery (UUCP), B.ALLBERY (GEnie) BrandonA (A-Online) ("...and a partridge in a pear tree!" ;-)