http://qs1969.pair.com?node_id=90333


in reply to Pasring XML into a simple hash

For a quick-and-dirty regexp solution, how about this...
while ($text =~ m|<jobnumber>(.*?)</jobnumber>.*?<location>(.*?)</loc +ation>|sg) { print "Found job number $1 in location $2 \n"; }
NB I'm assuming the missing slashes in the data are a typo. If not then it's easy enough to modify the above.

Of course, a regexp solution isn't the right one if you want it to work in more general cases - like if the tags are the other way round, or whatever. If there's going to be any variation in the data, then the way to go is an XML parser as described by others above.

andy.

Some Time Later: Just For Fun, I tried to see if I could write one that /would/ work with the tags either way round... came up with this...

my $regexp = '<post>'; $regexp .= "(?=.*?<$_>(.*?)</$_>)" foreach qw(jobnumber location); $regexp .= '.*?</post>'; while ($stuff =~ m|$regexp|sog) { print "Found job number $1 in location $2 \n"; }