【发布时间】:2018-07-16 13:54:01
【问题描述】:
我想比较 csv 中的值单独。在此代码示例中,我比较哈希值、Compare values in csv files,但对于我的 PUT 和 POST 请求我需要单独的值。
output1.csv (name, ip) - 主系统
Test1, 10.56.7.13
Test2, 10.56.4.14
Test3, 10.56.5.15
output2.csv (id,name,ip) - 辅助系统
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
400 Bad Request
400 Bad Request
200 OK
200 OK
400 Bad Request
Devices should be added: TEST_3
其实我在等:
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 request,所以ipaddress 应该从10.56.4.10 更改为10.56.4.14。
但我认为我的问题是,我错误地区分了我的价值观。
【问题讨论】: