perl alias

OK, it's probably not called an alias but I don't know the proper term.
I've been exploring prime number generation algorithms and after putting
the various routines in primes.pm I thought it would be neat to name the
fastest simply primes as so:

# set up an alias for the fastest prime generator
*primes = \&sieve_eratosthenese_lucky;

and export primes but it doesn't work:
Undefined subroutine &main::primes called at ./primes.pl line 176

I can put the same statement in a file that imports
sieve_eratosthenese_lucky but that's not what I really wanted.

Is there a way to setup such an alias in the *.pm that will
be correctly exported or am I faced with having to rename
the fastest routine?

Thanks,
Mike
--
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Mike McClain [ Sa, 11 Juni 2011 22:15 ] [ ID #2060918 ]

Re: perl alias

>>>>> "BF" == Brian Fraser <fraserbn [at] gmail.com> writes:

BF> On Sat, Jun 11, 2011 at 5:15 PM, Mike McClain <mike.junk [at] cox.net> wrote:
>>
>> # set up an alias for the fastest prime generator
>> *primes = \&sieve_eratosthenese_lucky;
>>
>>
BF> Just use that, but wrap it in a BEGIN block.

that isn't going to help. we don't see the actual code doing the
export. here is a working example from File::Slurp:

[at] EXPORT_OK = (
[at] edit_export,
qw(
slurp
prepend_file
),
) ;


*slurp = \&read_file ;

you need to export the aliased name as well as the original one. either
can be in EXPORT or in EXPORT_OK.

uri

--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Uri Guttman [ So, 12 Juni 2011 05:58 ] [ ID #2060938 ]

Re: perl alias

On Sat, Jun 11, 2011 at 01:15:45PM -0700, Mike McClain wrote:
<snip>
> # set up an alias for the fastest prime generator
> *primes = \&sieve_eratosthenese_lucky;
>
> and export primes but it doesn't work:
> Undefined subroutine &main::primes called at ./primes.pl line 176
<snip>

Brian, Uri thanks for your help.
I'd have responded earlier but the mails dropped an edition or two of
the Beginners Digest and I had to go to the archives to see your
responses.

I got caught by the fact that a module's default exports aren't
exported if items from [at] EXPORT_OK are requested.

Mike
--
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Mike McClain [ Do, 16 Juni 2011 17:25 ] [ ID #2061178 ]
Perl » gmane.comp.lang.perl.beginners » perl alias

Vorheriges Thema: help: segmentation fault in threads program that use binmode
Nächstes Thema: Convert HTML to PDF