[OSM-dev] Split osm line with perl

2009-11-29 Thread Maarten Deen
Does anyone have an idea (or is there already a routine) how to split a line of an osm file in its respective keys and values? I've tried a few things, but I'm not fluent in perl. My problem at the moment is that splitting a line on the space character seems logical, but you run into problems

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Lennard
Maarten Deen wrote: I've tried a few things, but I'm not fluent in perl. My problem at the moment is that splitting a line on the space character seems logical, but you run into problems if a value has a space in it. So splitting something like tag k=name v=foo bar/ will split the value

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Dave Stubbs
On Sun, Nov 29, 2009 at 11:41 AM, Lennard l...@xs4all.nl wrote: Maarten Deen wrote: I've tried a few things, but I'm not fluent in perl. My problem at the moment is that splitting a line on the space character seems logical, but you run into problems if a value has a space in it. So

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Lennard
Dave Stubbs wrote: And then hope that the attributes are in the order you're expecting, and that the XML has used rather than '. And in the example code given below hope that only one space was used. Adding that to the example code I gave would detract from the actual matching of what he

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Simone Cortesi
On Sun, Nov 29, 2009 at 12:16, Maarten Deen md...@xs4all.nl wrote: I've tried a few things, but I'm not fluent in perl. My problem at the moment is that splitting a line on the space character seems logical, but you run into problems if a value has a space in it. wouldnt be wiser to use a

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Frederik Ramm
Hi, Dave Stubbs wrote: The real trick of course is to use an XML parser which handles all of this for you. And decodes UTF8 along the way, and all this in just a few hours if you're lucky (if you happen to use the native Perl XML parsing which is used by default and without warning unless

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Anthony
On Sun, Nov 29, 2009 at 6:41 AM, Lennard l...@xs4all.nl wrote: Difficulty: are values with quotes allowed in k/v pairs? Yes, but they are escaped (usually as quot;). ___ dev mailing list dev@openstreetmap.org

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Anthony
On Sun, Nov 29, 2009 at 6:41 AM, Lennard l...@xs4all.nl wrote: $str =~ /k=([^]*) v=([^]*)/; If you don't care about order or number of spaces or anything like that, a simple if ($line=~/^tag k=(.*) v=(.*) /$/) will do. The code I gave was actually for parsing changeset and node tags, which

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Ævar Arnfjörð Bjarmason
On Sun, Nov 29, 2009 at 12:10, Simone Cortesi sim...@cortesi.com wrote: On Sun, Nov 29, 2009 at 12:16, Maarten Deen md...@xs4all.nl wrote: I've tried a few things, but I'm not fluent in perl. My problem at the moment is that splitting a line on the space character seems logical, but you run

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Frederik Ramm
Hi, Ævar Arnfjörð Bjarmason wrote: If I were to acquaint myself with it I'd be sure not to start by writing the millionth buggy tagsoup parser using regexes though. As I said, a good craftsperson will know all available tools and choose the one that best suits the job, and not disregard a

Re: [OSM-dev] Split osm line with perl

2009-11-29 Thread Ævar Arnfjörð Bjarmason
On Sun, Nov 29, 2009 at 18:43, Frederik Ramm frede...@remote.org wrote: Ævar Arnfjörð Bjarmason wrote: If I were to acquaint myself with it I'd be sure not to start by writing the millionth buggy tagsoup parser using regexes though. As I said, a good craftsperson will know all available