Aliasing built-in Functions
codeacrobat
created: 2006-03-19 11:05:18

Hi monks,

I thought about writing a module, which allows an easy way to alias perl built-in functions.

For example the bless function an evil monk would not want to use all day, but he might be happy to curse or damn the references.

use Acme::Alias bless => [qw(curse damn)];
my $string = "foo";
my $obj = curse \$string, 'CursedString';
my $obj2 = damn \$string, 'DamnedString';

My feeling is that that somewhere on CPAN a module with this functionality should exist. However I did not find it. Do you happen to know such a module?

Alternatively one could upload:

package Acme::Alias;

use Filter::Simple;
use strict;
use warnings;

our $VERSION = '0.01';
our %Symbols = ();

sub import()
{
    shift;
    my %all = @_;
    for (keys %all){
        if ( ref($all{$_}) eq 'ARRAY'){
             $Symbols{$_} = join q(|), @{$all{$_}};
        } else {
             $Symbols{$_} = $all{$_}
        }
    }

}

FILTER_ONLY
        code      => sub {
                           while (my ($key,$val) = each %Symbols){
                               s/$val/$key/gs;
                           }

};
1;
Re: Aliasing built-in Functions
created: 2006-03-19 11:20:49

Yeah, that'd be right up there with "#define BEGIN {" and "#define END }" for the unrepentant Pascal programmers moving to C on the list of good programming practices.

Re: Aliasing built-in Functions
created: 2006-03-19 12:58:34
It has been done, see Acme::Lingua::Pirate::Perl

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Re^2: Aliasing built-in Functions
xdg
created: 2006-03-19 16:09:23

And the classic Lingua::Romana::Perligata.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Aliasing built-in Functions
created: 2006-03-19 13:05:42

I think this is generally a bad idea. Aliasing builtins may be fun, and may give you some builtins with names you like better, but it probably causes more trouble than it's worth. It makes it extrememly difficult for someone to maintain your code, for example. They're looking for Perl words and finding yours. In order to ensure they're properly understanding, they have to track back and forth through the code to find what your aliases are referring to.

If you prefer another language, use it. Then use a translator to convert your code into Perl, if that's what you want to do. You could even write your own translator to do this for you. But aliasing builtins is just asking for trouble, IMNSHO.

Re^2: Aliasing built-in Functions
created: 2006-03-19 17:33:17

He did put it in the ACME name space which i thought made it pretty clear he was just playing around. ;)


___________
Eric Hodges
Re: Aliasing built-in Functions
created: 2006-03-19 16:47:11

Acme::Damn? Oh no, wait...

Re: Aliasing built-in Functions
created: 2006-03-19 18:31:34
This question has come up before: node 241938

In that thread, the OP admitted that the real purpose for aliasing a built-in function was as an aid in creating obfuscated code. It sounds a bit like that is your goal as well (or maybe you're just striving for poetry)? Obviously an admirable pursuit, but... well, have fun with that.

Re^2: Aliasing built-in Functions
created: 2006-03-21 14:34:38
Indeed, I was just learning about code filtering and wanted to start some poetry.
I wonder how it actually looks like to read lots of OO-code where objects get damned and cursed.
Or where filehandles do not get gently closed but shutuped.
Imagine we would go fishing if we mean to grep something.
Aliasing builtins is for fun (and only that).

perlmonks.org content © perlmonks.org and ambrus, codeacrobat, eric256, Fletch, graff, rinceWind, spiritway, xdg

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03