On 2010.04.28 22:04, Harry Putnam wrote:

> Your reference to `call back' is probably just the ticket... but I
> will show actual code that tries to do what I need, and maybe you can
> show how a `call back would work. 

This is pretty simple and has no inherent complexity whatsoever, but
hopefully it will make some sense. Essentially, I have one of the subs
that are included in the dispatch table that directly calls another sub
within the same table.

First note that this will run forever :)

Also, there's no proper conditional logic involved here, the dispatch
table subs are just calling back to other subs from within the dispatch
table randomly. Hopefully it gives you an idea of what I was trying to say.

Use:

# ./dt.pl N (where N == 1, 2 or 3)

#!/usr/bin/perl

use warnings;
use strict;

my $input = $ARGV[0];

my %dt = (
        1   => \&a,
        2   => \&b,
        3   => \&c,
);

sub a {

    my $param = shift;

    print "1\n";

    my $num = get_num();

    $dt{ $param }( $num );
}

sub b {

    my $param = shift;

    print "2\n";

    my $num = get_num();

    $dt{ $param }( $num );
}

sub c {

    my $param = shift;

    print "3\n";

    my $num = get_num();

    $dt{ $param }( $num );
}

sub get_num {
    return int( rand( 3 ) +1 );
}

$dt{ $input }( $input );

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