perl alias

perl alias

am 11.06.2011 22:15:45 von Mike McClain

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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: perl alias

am 12.06.2011 05:58:46 von Uri Guttman

>>>>> "BF" == Brian Fraser writes:

BF> On Sat, Jun 11, 2011 at 5:15 PM, Mike McClain 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:

@EXPORT_OK = (
@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@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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: perl alias

am 16.06.2011 17:25:34 von Mike McClain

On Sat, Jun 11, 2011 at 01:15:45PM -0700, Mike McClain wrote:

> # 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


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 @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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/