http://www.perlmonks.org?node_id=24492

Not at all sure why anyone would want to do this - I really wrote it to see how well I understood typeglobs and AUTOLOAD :)

What it does is allow you to call subroutines in your script using names that only match approximately. Currently this means that they have the same soundex value as generated by Text::Soundex.

As I said above, there's really no good reason at all why you'd ever want to do this and it will make your code completely unmaintainable, but it's just a bit of fun. Here's a sample program showing how you'd use it.

use strict; use Sub::Approx; sub aa { print "You called 'aa'\n"; } &a;

In this example, &a doesn't exist so &aa gets called instead as 'a' and 'aa' both have the soundex value of 'A000'

Enjoy...

Update:

I've uploaded this module to CPAN. You can get it at search.cpan.org/search?dist=Symbol-Approx-Sub

package Sub::Approx; use strict; use vars qw($VERSION $AUTOLOAD); use Text::Soundex; $VERSION = '0.01'; sub import { no strict 'refs'; # WARNING: Deep magic here! my $pkg = caller(0); *{"${pkg}::AUTOLOAD"} = \&AUTOLOAD; } sub AUTOLOAD { my %cache; my @c = caller(0); my ($pkg, $sub) = $AUTOLOAD =~ /^(.*)::(.*)$/; no strict 'refs'; # WARNING: Deep magic here! foreach (keys %{"${pkg}::"}) { my $glob = $::{$_}; $glob =~ s/^\*${pkg}:://; push @{$cache{soundex($glob)}}, $glob if defined &{"*${pkg}::$glob +"}; } $sub = soundex($sub); if (exists $cache{$sub}) { my @f = @{$cache{$sub}}; $sub = "${pkg}::$f[rand @f]"; goto &$sub; } else { die "REALLY Undefined subroutine $AUTOLOAD called at $c[1] line $c +[2]\n"; } } 1;