2007/10/9, yitzle <[EMAIL PROTECTED]>: > Can you pass a subroutine as a string or pointer or store it inside a > variable? > example (probably doesn't work, but that's not the point): >
Hi, I'd better to do it by passing subroutine's reference to another routine. #!/usr/bin/perl use strict; use warnings; sub func1 { my $i = shift; return $i =~ /^[0-9]+$/; } sub func2 { my $i = shift; return $i =~ /^[a-z]+$/; } sub test { my ($function, $description, $var, undef) = @_; print $description . ": "; print $function->($var) ? "Yes\n" : "No\n"; } my $input = <>; test(\&func1, "Numeric", $input); test(\&func2, "Lower", $input); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/