[Israel.pm] exporting all the functions in a module
Shlomi Fish
shlomif at iglu.org.il
Tue Feb 1 06:54:49 PST 2005
On Monday 31 January 2005 20:17, Gaal Yahas wrote:
> On Mon, Jan 31, 2005 at 07:56:50PM +0200, Shlomi Fish wrote:
> > my %remove = (map { $_ => 1 } (qw(BEGIN INIT import CHECK DESTROY
> > END)));
>
> Of these, only DESTROY and import do anything. The rest are not subs.
I don't know if they are subs or not, but they do appear in the symbol table:
<<<
package ListAll;
use strict;
use warnings;
sub import
{
{
no strict 'refs';
my @funcs =
sort { $a cmp $b }
keys(%{__PACKAGE__."::"});
print map { "$_\n" } @funcs;
}
}
INIT
{
1;
}
use vars qw($myvar);
sub add
{
my ($c, $d) = (@_);
return ($c+$d);
}
use vars qw($aloha);
sub aloha
{
print "Aloha!\n";
}
sub cond
{
my ($cond, $true_val, $false_val) = (@_);
return ($cond ? $true_val : $false_val);
}
sub yowza
{
my $n = shift;
if ($n <= 1)
{
return 1;
}
return $n * yowza($n-1);
}
1;
>>>
using it prints:
<<<
BEGIN
INIT
a
add
aloha
b
cond
import
myvar
yowza
>>>
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://www.shlomifish.org/
Knuth is not God! It took him two days to build the Roman Empire.
More information about the Perl
mailing list