fork download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my %hash = (
  6. key1 => "value1",
  7. key2 => sub {
  8. return "value2"; # In the real code, this value can differ
  9. },
  10. );
  11.  
  12. sub evaluate {
  13. my $val = shift;
  14. return $val->() if ref($val) eq 'CODE';
  15. return $val; # otherwise
  16. }
  17.  
  18. foreach my $key (sort keys %hash) {
  19. print evaluate($hash{$key}) . "\n";
  20. }
Success #stdin #stdout 0s 6176KB
stdin
Standard input is empty
stdout
value1
value2