开发者

How can I pass Twig sub parameter?

开发者 https://www.devze.com 2023-02-01 18:45 出处:网络
Help I can\'t pass my hash key to twig subroutine. here: foreach my $word (sort { $keywords{$a} <=> $keywords{$b} } keys (%keywords)) {

Help I can't pass my hash key to twig subroutine.

here:

foreach my $word (sort { $keywords{$a} <=> $keywords{$b} } keys (%keywords)) {
my $t = XML::Twig->new( twig_roots   => { 'Id' => \&insert($keywords{$word}) } );

    $t->parse($docsums);

    sub insert 
    { 
      开发者_运维问答  my($t, $id, $k)= @_;

        my $p =  $id->text;      

        my $query    = "insert into pres (id, wid, p) values(DEFAULT, '$k', '$p')";
        my $sql      = $connect->prepare($query);
        $sql->execute( );   

    }
}

Thanks.


Looks like you're trying to curry insert but Perl doesn't directly support that. Instead, you can use an anonymous sub to build the proper argument list for insert:

'Id' => sub { insert($_[0], $_[1], $keywords{$word}) }
0

精彩评论

暂无评论...
验证码 换一张
取 消