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

${$varname} works by looking in the local package for that variable name. Since you've used my, your variables won't be found there.

To achieve your stated immediate aim here of assigning to the variables you just assigned to (this "zero padding" is itself not a great idea, use the proper timestamp idea instead), you'd do:

$_ = zeropad($_) for $sec, $min, $hour, $day, $month;
But that itself won't affect the "timestamp" (how could it?). If you wanted a Unix timestamp with zeroes for those values, you'd just do something like:
my ((undef) x 5, $year, $wday, $yday, $isdst) = localtime(time); my $zeroed_ts = timelocal((0) x 5, $year, $wday, $yday, $isdst);

Replies are listed 'Best First'.
Re^2: What's so wrong with this (dereferencing)code?
by Maelstrom (Beadle) on Jun 26, 2024 at 13:01 UTC
    That line was exactly what I was looking for. Much elegance! As for affecting the time stamp I'm talking about using it an integer with no separators not a string. It currently returns as..
    get_date('timestamp'); 20240626204609 get_date('timestamp', { sep=>':' }); 2024:6:26:20:46:9
    I'm not doing any padding in the second case (although I note even the POSIX function pads with spaces by default). I could probably just use the output of time for the first case but it's human readable and happens to be the way I've always used time stamps when typing them by hand.