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

If you want to generate timestamps, then generate timestamps:
use POSIX qw( strftime ); my $timestamp = strftime('%Y-%m-%d %H:%M:%S', localtime);

Replies are listed 'Best First'.
Re^2: What's so wrong with this (dereferencing)code?
by Maelstrom (Beadle) on Jun 26, 2024 at 11:46 UTC
    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.

      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.
      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".