Re: How good is PERL at searching ASCII files?
- From: boyd <tbmoore9@xxxxxxxxxxx>
- Date: Thu, 07 Dec 2006 16:11:36 GMT
In article <1165506343.745473.254360@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
jmartzoo-google@xxxxxxxxx wrote:
Hi,
Please forgive my ignorance, I'm a C language developer but I've got
some text manipulation that needs doing and I've heard many times that
this is PERL's forte. That being said, I'd like to give it a try
instead of writing a C# app to deal with this. Can PERL do th
following relatively easy, or should I just spend 3 or 4 hours writing
a C# algorithm?
The challenge I'm faced with is to search out all occurrences where a
function named CONVERT() is being called with three parameters. It's a
challenge because the function has several signatures and I need to
segregate the three param calls from the two param calls. To make
things even spicier, it's very possible that the parameters may also be
function calls themselves. I think the best strategy becomes finding
the pattern:
CONVERT(<something>,<something>,
The key elements being the string CONVERT, one open paren ( followed by
two commas at the same nesting level.
...
Much obliged,
John M
Montreal, Quebec
Perl is very good at that. However, I'm not. The Perl module,
Text::Balanced is tailored for this very task. I can help you learn to
use it (while I learn it myself).
Or you can use the regexp of Perl to do this quite easily, I suspect,
but I haven't done that with multiple lines before.
I guess my approach would be to find the CONVERT call, then keep reading
lines until the count of the occurences "(" and ")" balance out, using
the '.' operator to join the lines together into one string. Then use a
regexp to determine whether the number of parameters was 2 or 3. Or,
better, that determination could be done as you do the counting...
Oops - that latter thought gets more complicated if you have extra
parentheses as in:
CONVERT((1),1,(((3)))). Oh well - I would then, at that point, realize
that to make it bullet proof would take more time and testing than just
learning to use Text::Balanced.
Boyd
.
- Follow-Ups:
- References:
- How good is PERL at searching ASCII files?
- From: jmartzoo-google
- How good is PERL at searching ASCII files?
- Prev by Date: Re: HASH
- Next by Date: Re: cscope for perl
- Previous by thread: How good is PERL at searching ASCII files?
- Next by thread: Re: How good is PERL at searching ASCII files?
- Index(es):