Gunnar Hjalmarsson wrote:
Randal L. Schwartz wrote:

Gunnar Hjalmarsson writes:


/(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;


That's an alternative, but would it necessarily be better? To me,
using a module for such a trivial thing just creates another
level of abstraction without actually making it easier.


Can we agree to disagree on that?


Sure.

Once you understand Regex::Common, it becomes a nice abstraction. Having said that, I don't yet. :)


Please feel free to like any module you don't understand. ;-)

I for one concentrate on learning - and practicing - the basic regex
syntax. That way I get better prepared when I need to write less
common regexes.

But that's me. I'm not claiming that Regex::Common is not a useful
tool for those who like it. I'm rather saying that it should better be
considered a matter of personal preferences, rather than a matter of
preferred programming style.

Can we possibly agree on that?

I understand your argument. It is very important to understand what is going on, to understand regexs well enough to construct ones like we're discussing now. In fact, I am an old school programmer with background in C & C++ and various other compiled & scripting languages. In generall, I believe that it is important to know how things are done under the hood as well so that you can know and evaluate the costs of using certain features & algorithms. I very much understand and agree with you that being able to understand and construct regexs is essential and that the use of modules should not be an excuse to avoid learning.


However, I do think taking advantage of modules such as Regexp::Common is also essential. The reason are the basically the same reasons we practice modular, object-oriented, and other programming methodologies: To isolate repeatedly used pieces of code so that it's use is consistent, changes & fixes are isolated, etc.

For example, let's say that over the course of a few years that you write several related scripts to munge a certain data store. Each time you write a script you have to construct a regex like the one discussed, to match numbers. Because of experience, learning, or even a mood swing on the day you write one of the scripts it's possible that you may use similar but subtlely different regexs. This can lead to subtle problems and not-so-subtle hair pulling.

I recommend modules like Regexp::Common because they consolidate and isolate common code in reusable chunks. It helps you write consistent code and code that is consistent with other authors. It isolates change so that if it doesn't behave the way you want, you can change that behaviour in a single place. If there is a bug, you know were to look. And it's great to know that if there is a bug, you can blame it on someone else. ;-)

I've used or played with many modules. I've got one machine that probably has about half of CPAN installed. I use it to test and evaluate modules, or just to take a peek at anything that looks like it might be interesting. There are very few modules that I highly recommend that are not either already part of core perl or specialized. Regexp::Common is one exception. IMO, it belongs in the core, and I don't say that lightly--I'm a minimalist. But, it solves a very popular subset of problems in a consistent, robust, and flexible way.

If that's not enough, let me point out that parsing numbers is not as straightforward as it might seem. Some of the things you must consider are: do you allow decimal? Is the decimal a comma or period? Do you allow numbers with no digit before the decimal? Do you allow negiative/positive indicators? Do you allow scientific notation? What about grouping (eg. 123,456.05)? What is the grouping symbol? How many digits in each grouping? etc. There is a lot of variation to consider. And it's already been considered by someone else in Regexp::Common.

Regards,
Randy.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to