ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Now, how do I find every instance of 'keyword { ... }' in a string and store it separately, including the prefix?
The documentation tells you about $extracted, $remainder, $prefix, doesn't it ? And if you agree with me that it does, doesn't the $remainder item ring the bell ? I.e. don't you think $remainder can be fed as $text as many times as one wants ?
I still think the easiest way would be to write my own simple, specialized parser for it, that would even understand C style comments and give more meaningful, compiler-like error messages.
But how do you iterate through the chars in a string in Perl?
I still think the easiest way would be to write my own simple, specialized parser for it, that would even understand C style comments and give more meaningful, compiler-like error messages.
But how do you iterate through the chars in a string in Perl?
perldoc -f substr
perldoc -f length
.
Plus remember that $prefix is returned too.
And no, don't reinvent the wheel - so far Text::Balanced has all you need, and you'll have to add minimum glue code.
There is Perl code understanding "C" comments around, and it's a FAQ.
Really ? Did you read ? Did you look for all occurrences of the word "comment" ?
...
Let me tell you something. When I studied English, I pretty quickly discovered that the appropriate meaning of an unknown to me word was not among the first meanings given by the dictionary.
The same applies to SW documentation - often the needed info is not in the beginning. According to my understanding, it is possible to suppress macro expansion while still processing comments.
Anyway, here is my current code, it first slurps the file, splices escaped newlines, writes it to a new file with the extension changes to ".c", runs cpp to extract the comments and write to a temp file, and then gets rid of the temp file.
The remarkable thing is that it worked perfectly the first try!!!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.