[Perl] Cutting text strings

Gaal Yahas gaal at forum2.org
Sat Feb 9 06:45:18 PST 2002

On Fri, Feb 08, 2002 at 09:13:19PM +0200, Pinkhas Nisanov wrote:

> It's better for cases when you have e-mail as more complicated string
> "Yaron Golan <yaron.golan at SeabridgeNetworks.com>".
> In case of simple substitute $user will have "Yaron Golan <yaron.golan",
> but in case Mail::Address module $user will get what we want "yaron.golan".

Yes, you're right; s/\@.*// does not deal with these cases. Since the
original poster didn't specify his requirements fully, I assumed he
meant the address part of the address. This assumption, mind you, is
also based on his own example of the tcsh code he uses today.

But I concede the point. Email addresses can contain a name section. I
therefore offer

($new = $address_with_possible_name_section) =~ s/(.*<)?(.*)\@.*/$2/;

as a revised proposal.

> This module also perform some e-mail validation.

Which is only as good--at best--as the use you put it to. Meaning, the
fact that it performs "some" e-mail validation demands applicative
attention. If that attention is not given, the validation is worth

> In general I think it is better way for solving some problem to use modules
> that already in use, even if it add some code lines.

I don't. I think that in many cases, this may be true; but not in
trivial ones. There are over 2,300 modules in CPAN today. Are you
suggesting that just because somebody wrote a module that happens
to do something my module needs, I use it? You'll get pretty
bloated software if you are consistent in this view.

Yes, code reuse is nice. But IMHO, it can be ignored if the problem
is simple enough.

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list