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;

Replies are listed 'Best First'.
Re: Aliasing built-in Functions
by rinceWind (Monsignor) on Mar 19, 2006 at 17:58 UTC
    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)

      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
by Fletch (Bishop) on Mar 19, 2006 at 16:20 UTC

    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
by graff (Chancellor) on Mar 19, 2006 at 23:31 UTC
    This question has come up before: Aliasing a builtin?

    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.

      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).
Re: Aliasing built-in Functions
by spiritway (Vicar) on Mar 19, 2006 at 18:05 UTC

    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.

      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
by ambrus (Abbot) on Mar 19, 2006 at 21:47 UTC