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;
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.
--
Oh Lord, wont 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, wont 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.
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.
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.
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