in reply to Re: What's so wrong with this (dereferencing)code?
in thread What's so wrong with this (dereferencing)code?

Timestamps are just one function of the function and I'm actually trying to deepen my knowledge of Perl rather than accomplish a specific task. For example why does this code work?
use POSIX; $now = POSIX::strftime("%a, %e %b %Y %T GMT",gmtime($now));
And this code doesn't?
require POSIX; $now = POSIX::strftime("%a, %e %b %Y %T GMT",gmtime($now));
I will be using strftime instead of rolling my own templates as even my frippery has it's limits but sometimes reinventing the wheel gets you a more efficient wheel. But once again I'm being bitten by Perls mind boggling inconsistency.

Replies are listed 'Best First'.
Re^3: What's so wrong with this (dereferencing)code?
by hippo (Archbishop) on Jun 26, 2024 at 13:06 UTC

    The first snippet "works" because it is calling POSIX::gmtime whereas the second is calling CORE::gmtime. Different functions behave differently.


    🦛

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: What's so wrong with this (dereferencing)code?
by Anonymous Monk on Jun 26, 2024 at 18:07 UTC
    POSIX docs warn that it imports everything by default, so either give it an import list, or give it an empty import list and fully qualify the functions:
    use POSIX 'strftime'; $now = strftime("%a, %e %b %Y %T GMT",gmtime($now)); use POSIX (); $now = POSIX::strftime("%a, %e %b %Y %T GMT",gmtime($now));
    Time::Piece docs say to use its version of strftime and strptime "without the overhead of the full POSIX extension".