Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:21:17+00:00 2026-05-15T20:21:17+00:00

strftime(), as per cpan.org: print strftime($template, @lt); I just can’t figure the right Perl

  • 0

strftime(), as per cpan.org:

print strftime($template, @lt);

I just can’t figure the right Perl code recipe for this one. It keeps reporting an error where I call strftime():

...
use Date::Format;
...
sub parse_date {
 if ($_[0]) {
  $_[0] =~ /(\d{4})/;
  my $y = $1;
  $_[0] =~ s/\d{4}//;
  $_[0] =~ /(\d\d)\D(\d\d)/;
  return [$2,$1,$y];
  }
 return [7,7,2010];
 }

foreach my $groupnode ($groupnodes->get_nodelist) {
    my $groupname = $xp->find('name/text()', $groupnode);
    my $entrynodes = $xp->find('entry', $groupnode);
    for my $entrynode ($entrynodes->get_nodelist) {
        ...
        my $date_added = parse_date($xp->find('date_added/text()', $entrynode));
        ...
        $groups{$groupname}{$entryname} = {...,'date_added'=>$date_added,...};
        ...
        }
    }
...

my $imday = $maxmonth <= 12 ? 0 : 1;
...

while (my ($groupname, $entries) = each %groups) {
    ...
    while (my ($entryname, $details) = each %$entries) {
        ...
        my $d = @{$details->{'date_added'}};
        $writer->dataElement("creation", strftime($date_template, (0,0,12,@$d[0^$imday],@$d[1^$imday]-1,@$d[2],0,0,0)));
        }
    ...
    }
...

If I use () to pass the required array by strftime(), I get:
Type of arg 2 to Date::Format::strftime must be array (not list) at ./blah.pl line 87, near “))”

If I use [] to pass the required array, I get:
Type of arg 2 to Date::Format::strftime must be array (not anonymous list ([])) at ./blah.pl line 87, near “])”

How can I pass an array on the fly to a sub in Perl? This can easily be done with PHP, Python, JS, etc. But I just can’t figure it with Perl.

EDIT: I reduced the code to these few lines, and I still got the exact same problem:

#!/usr/bin/perl

use warnings;
use strict;
use Date::Format;

my @d = [7,13,2010];
my $imday = 1;
print strftime( q"%Y-%m-%dT12:00:00", (0,0,12,$d[0^$imday],$d[1^$imday]-1,$d[2],0,0,0));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:21:18+00:00Added an answer on May 15, 2026 at 8:21 pm

    Where an array is required and you have an ad hoc list, you need to actually create an array. It doesn’t need to be a separate variable, you can do just:

    strftime(
        $date_template,
        @{ [0,0,12,$d[0^$imday],$d[1^$imday],$d[2],0,0,0] }
    );
    

    I have no clue why Date::Format would subject you to this hideousness and not just expect multiple scalar parameters; seems senseless (and contrary to how other modules implement strftime). Graham Barr usually designs better interfaces than this. Maybe it dates from when prototypes still seemed like a cool idea for general purposes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code I'm using is: import time print(time.strftime(%H:%M:%S)) In the dynamic shell, this (as
I have this code here import subprocess from time import strftime # Load just
I can output a locale sensitive time format using strftime('%X') , but this always
I have the following snippet of code: setlocale(LC_ALL, de); print(strftime(%A %e %B %Y, time()));
Consider this code: datestring = date.min.strftime(%d-%m-%Y) date = datetime.strptime(datestring,%d-%m-%Y) This raises the following error:
DATE1=`perl -e 'use POSIX qw(strftime); print strftime %Y-%m-%d,localtime(time()- 3600*72);'` DATE2=`perl -e 'use POSIX qw(strftime);
2011-09-13 is today (GMT+0) Date.UTC(<%= effort.week_commencing.strftime(%Y,%m,%d) %>) Outputs Date.UTC(2011,09,12) This is right because it
I have this variable: $timestamp = strftime(%Y-%m-%d %h:%M:%S %a, time ()); I simply want
I'm using dateString = date.strftime('%Y-%m-%d %H:%M:%S.%f') on this date: 2012-06-28 16:11:17 which returns 2012-06-28
I also have a week number, extracted from another time object like this other_time.strftime('%W').to_i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.