Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!stanford.edu!agate!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: package switching Message-ID: <1991May1.200904.3640@iwarp.intel.com> Date: 1 May 91 20:09:04 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 33 In-Reply-To: dnb@meshugge.media.mit.edu (David N. Blank) In article , dnb@meshugge (David N. Blank) writes: | How do I do it? I have seen Randall use this idiom: ======= s/l// # :-) | | > $ret = eval "package main; $action" | | but I would prefer not to stick the entire contents of a subroutine | into one scalar variable. Is there some magic way to expand the | scope of the package commands? Thanks. You could do something like: package smurf; sub whatIreallywannado { foo; foo; foo; } sub user_calls { eval "package $bar; &smurf'whatIreallywannado;"; die $@ if $@; } That way, what you are evalling is only a little piece of text instead of the whole thing. Does that make you happier? package Just_another_Perl_hacker;sub a{($_)=caller;s/_/ /g;print"$_,";}&a -- /=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: putting the 'backward' in 'backward compatible'..."====/