in reply to Parsing an file that has xml like syntax
#!/usr/bin/perl use warnings; use strict; sub output { my ($id, @jobs) = @_; print join("\t", $id, @{$_}{qw(JOBID TYPE FILE)}), "\n" for @jobs; } my @jobs; my $id; while (<>) { my ($tag, $value) = m{<(.*)>(.*)</\1>} or next; if ('PROJECT_ID' eq $tag) { output($id, @jobs); $id = $value; @jobs = (); } else { $tag =~ s/[0-9]+$//; $#jobs++ if 'JOBID' eq $tag; $jobs[-1]{$tag} = $value; } } output($id, @jobs); # Don't forget to output the last job.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing an file that has xml like syntax
by Anonymous Monk on Apr 02, 2014 at 19:20 UTC | |
|
Re^2: Parsing an file that has xml like syntax
by crusty_collins (Friar) on Apr 02, 2014 at 19:33 UTC | |
by Anonymous Monk on Apr 02, 2014 at 19:56 UTC |