in reply to Re: Parsing an file that has xml like syntax
in thread Parsing an file that has xml like syntax
Outputuse strict; use Data::Dumper; my $config; while (<DATA>) { chomp; my ($key, $variable)= ( $_ =~ /<(\w+?)>([^<]*)/); if ($key =~ m/JOBID/){ push (@{$config->{JOBID}},$variable); }else{ $config->{$key} = $variable; } } close FILE; print Dumper $config; __DATA__ <PROJECT_ID>12345</PROJECT_ID> <JOBID>101</JOBID> <JOBID>102</JOBID> <JOBID>103</JOBID> <TYPE1>add</TYPE1> <FILE1>/tmp/file_data_gros</FILE1> <JOBID>102</JOBID> <TYPE2>delete</TYPE2> <FILE2>/tmp/file_myvalues</FILE2>
$VAR1 = { 'JOBID' => [ '101', '102', '103', '102' ], 'FILE2' => '/tmp/file_myvalues', 'TYPE2' => 'delete', 'FILE1' => '/tmp/file_data_gros', 'TYPE1' => 'add', 'PROJECT_ID' => '12345' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parsing an file that has xml like syntax
by Anonymous Monk on Apr 02, 2014 at 19:56 UTC |