Reply to post: Re: Why exactly is Perl any worse than Python? : About efficiency.

Clutching at its Perl 6, developer community ponders language name with less baggage

bombastic bob Silver badge

Re: Why exactly is Perl any worse than Python? : About efficiency.

Unless you're writing a compiler from scratch, you don't need flex/bison to parse log files.

agreed. But I wouldn't use those libs for a compiler either. Bloatware. unnecessary.

parsing text files with a pair of pointers is easy. Typically I'll write a function like this:

char *p1 = the_buffer;

char *p2;



while(*p1 && *p1 <= ' ') p1++; // ltrim

p2 = p1;

while(*p1 > ' ') p1++; // end of term

// pass p1 and p2 to a function that copies or compares

// if((p1 - p2)==5 && !strncmp(p2, "thing", 5)) <-- string 'thing' is first term


not hard. look for '\n' to terminate a line. in fact, simple. pretty bullet proof, too. You're welcome. I do this a LOT.

you can also use scanf if you only want simple parsing.

if you need something more complex, you can parse columns and/or quoted strings pretty easily. I've even witten a full blown XML parser. It could fit on a microcontroller if it had to. I've seen similar kinds of simple parsers used for JSON [not written by me] so there are others out there doing this sort of thing. The fact is that string parsing is NOT hard, there are basic techniques you can use (like what I did above, the 2 pointer method), and you can use standard libc functions and pointers to parse just about ANYTHING that's text. Switch to mbcs functions if you need that for UTF8, no big deal.

no need for bloatware, OR Python. Or special Perl modules, either.

''awk' does a good job too.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon


Biting the hand that feeds IT © 1998–2019