Perl 在csv中具有单独值的HTTP PUT请求
我想比较csv中的值单独的。在这个代码示例中,我比较哈希值,但是对于PUT和POST请求,我需要单独的值 output1.csv(名称,ip)-主系统Perl 在csv中具有单独值的HTTP PUT请求,perl,csv,parsing,hash,Perl,Csv,Parsing,Hash,我想比较csv中的值单独的。在这个代码示例中,我比较哈希值,但是对于PUT和POST请求,我需要单独的值 output1.csv(名称,ip)-主系统 Test1, 10.56.7.13 Test2, 10.56.4.14 Test3, 10.56.5.15 1234,Test1, 10.56.7.13 1235,Test2, 10.56.4.10 output2.csv(id、名称、ip)-辅助系统 Test1, 10.56.7.13 Test2, 10.56.4.14 Test3, 10
Test1, 10.56.7.13
Test2, 10.56.4.14
Test3, 10.56.5.15
1234,Test1, 10.56.7.13
1235,Test2, 10.56.4.10
output2.csv(id、名称、ip)-辅助系统
Test1, 10.56.7.13
Test2, 10.56.4.14
Test3, 10.56.5.15
1234,Test1, 10.56.7.13
1235,Test2, 10.56.4.10
我的结果应该是:
- 不要对Test1执行任何操作(因为它已经在系统2中)
- 更新Test2(因为现在我有了不同的ip地址)
- 添加Test3,因为我在辅助系统中没有它
其实我在等:say "UPDATE need be done for $second{$name}"; #Now I want to make PUT (Update) request for these devices in secondary systen. open ( my $input_1, '<', 'output1.csv' ) or die $!; while ( <$input_1> ) { chomp; my ($name_1, $ip_1) = split /,/; my $xml = XML::Twig -> new -> parsefile ( 'template.xml' ); $xml ->set_pretty_print('indented_a'); open ( my $input_2, '<', 'output2.csv' ) or die $!; while ( <$input_2> ) { chomp; my ($id, $name, $ip) = split /,/; $xml -> root -> set_att('name', $name); $xml -> get_xpath('//ipaddress',0) -> set_text($ip_1); my $uri="https://hostname:9060/ers/config/networkdevice/$id"; my $req = HTTP::Request->new('PUT', $uri,[Accept=>'application/vnd.com.cisco.ise.network.networkdevice.1.1+xml', Content_Type=>'application/vnd.com.cisco.ise.network.networkdevice.1.1+xml; charset=utf-8'], $xml->sprint); $req->content($xml->sprint); $req->authorization_basic("user", "user"); #Pass request to the user agent and get a response back my $res = $ua->request($req); #Check the outcome of the response if ($res->is_success) { print $res->status_line, "\n"; } else { print $res->status_line, "\n"; } } }
因为要使用Match found TEST_1, 10.66.12.5 UPDATE need be done for 10.66.10.4 200 OK Devices should be added: TEST_3
执行1235、Test2,10.56.4.10
,PUT请求
应该从ipaddress
更改为10.56.4.10
但我认为我的问题是,我把我的价值观划分错了10.56.4.14
将产生:my $id, $first{$name}, $second{$name} = split /,/;
您在运行代码时是否确实读取了错误消息 应该是:Useless use of hash element in void context ....
( my $id, $first{$name}, $second{$name} ) = split /,/;
它现在从
获取值并进行更新(无更改)。我需要将output2.csv
中的IP地址更改为output1.csv
设备中的IP地址。output2.csv:Test2 name
1234,Test1,10.56.7.13 1235,Test2,10.56.4.14