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 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 tools and ch

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 12:10, Simone Cortesi wrote: > On Sun, Nov 29, 2009 at 12:16, 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

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

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

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

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

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

2009-11-29 Thread Anthony
On Sun, Nov 29, 2009 at 6:16 AM, Maarten Deen wrote: > 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? On Sun, Nov 29, 2009 at 6:16 AM, Maarten Deen wrote: > Does anyone have an idea (or is there already a routin

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 y

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

2009-11-29 Thread Simone Cortesi
On Sun, Nov 29, 2009 at 12:16, 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. wouldnt be wiser to use a DOM/XML parser

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 Dave Stubbs
On Sun, Nov 29, 2009 at 11:41 AM, Lennard 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 splitting

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 will split the value > "foo bar" also.

[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