# This array of hashes keeps track of all test results my @tests = ( { name => 'Ping Test', subname => \&pingtest, result => 'Not performed' }, { name => 'Remdial', subname => \&remdial, result => 'Not performed' } ); # Loop through array of hashes and perform each test subroutine. foreach $x (@tests){ # Call subroutine. # What is the correct way to state this? # Without the references I would normally state # $result = testsub(); $x->{'result'} = $x->{'subname'}->(); print $x->{'result'}."\n"; # Stop testing if there is a failure. if ($x->{'result'} =~ m/Fail/) { last; } } sub pingtest {print "ping\n"; return 123} sub remdial {print "dial\n"; return 456}
Output:
ping 123 dial 456
In reply to Re: Syntax to call a subroutine from a reference
by chester
in thread Syntax to call a subroutine from a reference
by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |