Hi, Here is something to think about, I 'm not even sure it's possible.
>>>>>>>>>>>>>>>>> package first ; sub first_one {print "1\n" ; first_two()} ; sub first_two {print "2\n" ; print join(':', caller()) . "\n"} ; our @x ; package second ; $import_from = 'first' ; for $symbole_name (keys %{"$import_from\::"}) { local *symbole = "$import_from\::"->{$symbole_name} ; print "$symbole_name " ; if(defined *symbole{CODE}) { print "is code" ; *{__PACKAGE__ . "\::$symbole_name"} = \&{"$import_from\::$symbol +e_name"} ; } print "\n" ; } first_one() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
This prints:
first_two is code
x
first_one is code
1
2
first:/home/nadim/Desktop/test.pl:4
a little explaination, I declare 2 subs in a package then I alias them into another package. I'd be glad to see how you write it if you have a better syntax. sub first_two prints from which package it's called. That is invariably package 'first'. The sub resides in its declaration package and even though the alias is in another package the call is done in the original package. I have no particular problem with that except that I would have find it nicer (and right) to have the call made in the aliasing package. My questions are: Is there a way to force a function call (an alias) into a package?
SetPackageAndCall("ihha", \&first_one, arg1, arg2)
Is there a way to modify the package while inside the sub? Fiddling with the stack? overriding 'caller'?
>>>>>>>>>> package first ; sub first_one { my $package = shift ; SetMyPackage($package) ; first_two() ; } sub first_two { sub first_two {print "2\n" ; print join(':', caller()) . "\n"} ; } package second ; # import the subs as before first_one('a_completely_diffrent_package') ; <<<<<<<<<<<<<< the above would print: a_completely_diffrent_package:/home/nadim/Desktop/test.pl:4 I'm all ears, Nadim. PS. there is a practical use that I'll gladely if someone is interrested.

edited: Thu Jun 10 21:05:22 2004 by jeffa - formatting


In reply to Playing with package spaces by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.