Perl: unable to pass array on the fly

strftime (), according to cpan.org:

print strftime($template, @lt);

I just can't figure out the correct Perl code recipe for this. It keeps reporting an error when 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 strftime () array, I get: Type arg 2 to Date :: Format :: strftime should be an array (not a list) in the string. /blah.pl 87 next to "))"

If I use [] to transfer the required array, I get: Type arg 2 to Date :: Format :: strftime should be an array (not an anonymous list ([])) in the string. /blah.pl 87, next to "])"

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

EDIT: , :

#!/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));
+5
4

, . , :

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

, Date:: Format , ; ( , strftime). , . , , - .

+7

, , ,

print "@{[1, 2, 3]}\n";

1 2 3

Date::Format::strftime funky prototype:

print strftime(q"%Y-%m-%dT12:00:00",
               @{[0,0,12,$d[0^$imday],$d[1^$imday]-1,$d[2],0,0,0]});

:

1900-24709920-00T12:00:00
+3

" " Perl. Date::Format::strftime - ($\@;$), "list" " ":

strftime($format, (0,0,12,13,7-1,2010-1900));      # not ok
strftime($format, @a=(0,0,12,13,7-1,2010-1900));   # not ok

, strftime .

my @time = (0,0,12,13,7-1,2010-1900);   # note: @array = ( ... ), not [ ... ]
strftime($format, @time);
+2

, :

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)));

@{$details->{'date_added'}} . , :

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)));

@d ($d[ ... ] @$d[ ... ])

0

All Articles