in reply to Variable behaving as a function call

Hi dirtdog,

I believe you are looking for a CODEREF. You could do:

my $time_zone_func = ( $file =~ /^London/ ) ? sub { gmtime shift } : sub { localtime shift };
to create a reference to an anonymous subroutine.

You dereference the coderef with &{ $ref } so you would call it as:

$foo = &$time_zone_func( time );
or
$bar = $time_zone_func->( time );

Hope this helps!


The way forward always starts with a minimal test.