Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Perl the best choice for most string manipulation tasks?

I've heard that Perl is the go-to language for string manipulation (and line noise ;). Can someone provide examples and comparisons with other language(s) to show me why?

like image 509
RCIX Avatar asked Sep 29 '09 05:09

RCIX


People also ask

Why is Perl good for text processing?

Perl's very rich and powerful regular expression (regex) engine makes it easy to do basic string crunching, but by adding a few community-created modules, you can manipulate all kinds of text-based resources. In fact, we've put together a Perl 5.28 runtime environment to support just that.

What is the best programming language for text processing?

The most popular scripting language in the world, Perl, is a superior text-processing language. Rexx also provides excellent string processing yet is much easier to learn and use.

Why is Perl popular?

Perl is very Unix-friendly. It can serve as a wrapper around Unix tools and is fully integrated into OS semantics. As a result, it excels at pipes, file slurping, inter-process communication, and other geeky tasks. It can create Unix daemons or server processes that run in the background.


2 Answers

It is very subjective, so I wouldn't say that Perl is the best choice, but it is certainly a valid choice for string manipulation. Other alternatives are Tcl, Python, AWK, etc.

I like Perl's capabilities because it has excellent support (better than POSIX as pointed out in the comment) for fast regexs and the implicit variables makes it easy to do basic string crunching with very little code.

If you have a *nix background a lot of what you already know will apply to Perl as well, which makes it fairly easy to pick up for a lot of people.

like image 173
Brian Rasmussen Avatar answered Oct 09 '22 02:10

Brian Rasmussen


Perl -> Practical Extraction and Reporting Language

Perl's strength(when it comes to string processing) lies in it's very powerful Regular expression engine.

Because of this there are many people in the field of BioInformatics using Perl as their main tool, hence the large number of posts about BioPerl on PerlMonks . In BioInformatics they work with strings a lot , they call them "sequences"(I don't know much about this).

Perlmonks.org is the heart of the Perl community, check out the immense number of hits when you search for site:perlmonks.org regex 20,000 hits

You cannot ignore the sheer number of modules on CPAN:

  • 375 modules under the namespace String on CPAN(Perl's module repository)
  • 241 in Regex namespace
  • 156 in Regexp namespace.

This is very clear evidence that Perl is a very powerful language when it comes to string processing.

So if you want to do some string processing and you're using Perl, you've got it covered :)

like image 28
xxxxxxx Avatar answered Oct 09 '22 02:10

xxxxxxx