-1

我有我的数据在一个数组中。我需要将数组值传递给ARSperlars_CreateEntry中的函数 。该数组是根据接收到的输入动态形成的,因此其长度可能会有所不同。

#!/usr/bin/perl

use strict;

use ARS;
use ARS::Login;

my $server   = '125.10.14.1';
my $username = 'RemedyUser';
my $dbsid    = $ENV{'ORACLEID'};
my $dbuser   = 'admin';
my $schema   = 'Form 1';

my $control = remedyars_login( $username )
        or die "ERROR: Cannot login to $server \n";
my $dbh = remedydbi_login( $dbsid, $dbuser )
        or die( "Cannot connect to $dbsid: $DBI::errstr\n" );

my @arr = ( 1, "New", 2, "Test", 3, "Hi" );
my $created_ticket = ars_CreateEntry( $control, $schema, join( ",", @arr ) )
        or die "ERROR: Cannot create host ticket: $ars_errstr\n";

ars_Logoff( $control );

当我运行脚本时出现此错误

错误:无法创建主机票证:[错误] 参数数量无效 (ARERR #80000)

4

1 回答 1

2

直接使用数组(参见ars_CreateEntry 示例):

my @arr=(1,"New",2,"Test",3,"Hi");
die unless @arr % 2 == 0; # enforce even number of elements in @arr
my $created_ticket=ars_CreateEntry( $control, $schema, @arr) 
  or die "ERROR: Cannot create host ticket: $ars_errstr\n";

如果 ars_CreateEntry 对参数的顺序不挑剔,甚至更好地使用哈希而不是数组:

my %params=(1 => "New",2 => "Test", 3 => "Hi");
# hash will be converted to array
my $created_ticket=ars_CreateEntry( $control, $schema, %params) 
  or die "ERROR: Cannot create host ticket: $ars_errstr\n";
于 2017-08-01T08:51:52.307 回答