Hello 1nickt,
Maybe you missed understand what I was writing / asking. I am asking what was his target in total. It looks like XY Problem
I never used it they way that you are using it, I would use it like this:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; sub print_timestamp { local *_get_formatted_time = sub { return $_[0] . uc scalar localtime; }; return _get_formatted_time(@_); } say print_timestamp('The time was: '); __END__ $ perl test.pl The time was: FRI AUG 25 15:18:08 2017
Instead of:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; print_timestamp('nigh'); print_timestamp( get_formatted_time() ); sub print_timestamp { say 'The time was ' . shift() } sub get_formatted_time { return uc scalar localtime } __END__ $ perl test.pl The time was nigh The time was FRI AUG 25 15:20:10 2017
Update: When you are calling a subroutine withing another subroutine like this:
sub a { sub b{ } }
It is basically the same as:
sub a { } sub b{ }
End of Update: So since he is try to test if a subroutine is safe (foo(bar()); # no errors reported - not expected behavior and foo(); # Undefined subroutine reported as expected). Why not simply calling it one by one, since it is the same thing if they are not defined locally?
But I suppose it depends the case. Thanks for sharing other ideas, BR.
In reply to Re^3: Safe module and undefined subroutines
by thanos1983
in thread Safe module and undefined subroutines
by bovlb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |