Hi all,

Given the threads on dispatch tables recently, I was writing a bit of a
whitepaper on how dts are useful for consolidating code.

I've run into an issue that I've been working on for some time (while
also performing my job function ;), and I'm hoping that extra eyeballs
will notice the problems.

Before I get elaborate in any which way with my documentation, I've just
been using a basic example (that you likely won't need to follow):

http://ipv6canada.com/code/dispatch_tables/dt1.pl.txt (and dt2.* and dt3.*)

Here is what I have that is breaking and I can't figure out why:

#!/usr/bin/perl

use warnings;
use strict;

use Tie::RegexpHash;

my $input   = $ARGV[0];

my $number  = qr/^\d+$/;
my $alpha   = qr/^\w+$/;

tie my %dt, 'Tie::RegexpHash';

%dt = (

        common  => sub {
                    my $param = shift;
                    print "$param\n";
                },

        $number => sub {
                    return int( rand( 3 ) +1 );
                },

        $alpha  => sub {
                    my @letters = ('a'..'z');
                    return $letters[ rand scalar @letters ];
                },

        run     => \&run,
    );

sub run {

    my $param   = shift;

    $dt{ common }( $param ) ;
    $dt{ run }( $dt{ $param } );
}

$dt{ run }( $input );

__END__

... I've never used Tie::RegexpHash before, so if you can see what I was
trying to do with it, I'm open to criticism.

Cheers,

Steve

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to