in reply to Using import to generate subroutines
how do I write my own "import" ?
This is one of the few cases where I think symbolic refs make things much easier. Here's how I'd probably do it:
package MyProcedures; use strict; use warnings; sub import { my $class = shift; my $caller = (caller)[0]; no strict 'refs'; for my $f (@_) { *{"$caller\::$f"} = sub { print "$f\n" }; } } 1;
And then it can be used like so:
$ perl -e 'use MyProcedures qw(one two three); one(); two(); three();' one two three
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using import to generate subroutines
by Thilosophy (Curate) on Nov 24, 2004 at 02:42 UTC | |
by fergal (Chaplain) on Nov 24, 2004 at 09:41 UTC | |
by revdiablo (Prior) on Nov 24, 2004 at 17:23 UTC | |
by fergal (Chaplain) on Nov 24, 2004 at 23:29 UTC | |
by diotalevi (Canon) on Nov 24, 2004 at 23:35 UTC | |
| |
by revdiablo (Prior) on Nov 25, 2004 at 01:04 UTC |