in reply to Re: Variable behaving as a function call
in thread Variable behaving as a function call

my $coderef = \&hiya; is far more conventional, but both are ok for subroutines.

Neither will work for operators such as gmtime and localtime, though.

Since 5.16:

my $time_zone_func = $file =~ /^London/ ? \&CORE::gmtime : \&CORE::localtime; strftime($date_format, $time_zone_func->(time))

Backwards compatible:

my $time_zone_func = $file =~ /^London/ ? sub { gmtime($_[0]) } : sub { localtime($_[0]) }; strftime($date_format, $time_zone_func->(time))
or
my $time_zone_func = sub { $file =~ /^London/ ? gmtime($_[0]) : localtime($_[0]) }; strftime($date_format, $time_zone_func->(time))

Replies are listed 'Best First'.
Re^3: Variable behaving as a function call
by AnomalousMonk (Archbishop) on May 11, 2016 at 19:35 UTC
    ... \&hiya; is far more conventional ... Neither will work for operators such as gmtime ...

    Oops... Should've remembered that one!


    Give a man a fish:  <%-{-{-{-<