note
mattr
If you don't have strict XML (i.e. no ending /location) tag
why not just use regular
expressions? This seems to work..
<CODE>
#!/usr/bin/perl
use strict;
open (IN,"testxml.dat");
my @buf = <IN>;
close IN;
for (my $i=0; $i<=$#buf; $i++) {
if ($buf[$i] =~ s/^\s*<jobnumber>(.*)<\/jobnumber>\s*$/$1/) {
$buf[$i+1] =~ s/^\s*<location>\s*(.*)\s<location>\s*$/$1/;
# if your tags are really like this
&process($buf[$i],$buf[$i+1]);
}
}
sub process {
my ($jobnumber,$location) = @_;
print "Found a job $jobnumber in $location.\n"; # do something
}
</CODE>
On a related note, I tried to lose the spaces inside the
location tags and couldn't get this kind of regex to work, anyone?
<CODE>
$buf[$i+1] =~ s/^\s*<location>\s*(.?)\s*<location>\s*$/$1/;
# \s?(.*)\s works though..
</CODE>
90287
90287