Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: subroutine as a parameter Message-ID: <1990Oct30.164045.26548@iwarp.intel.com> Date: 30 Oct 90 16:40:45 GMT References: <29351@pasteur.Berkeley.EDU> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 27 In-Reply-To: jhh@sprite.Berkeley.EDU (John H. Hartman) In article <29351@pasteur.Berkeley.EDU>, jhh@sprite (John H. Hartman) writes: | I'm trying to write my own sort routine that does a stable sort. | I can't figure out how to pass a subroutine as an argument. | Ideally my stable sort routine would take two parameters, the | comparison subroutine and the array to be sorted. Thanks. Does this help? ################################################## sub apply { local($function) = shift; do $function(@_); # call $function, passing remaining args } sub testit { print "args are <@_>\n"; } &apply("testit","arg","argg","arggh"); ################################################## print "Just another applied Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel put the 'backward' in 'backward compatible'..."=========/