Don Kim said:
Hmm. Does that mean there are functions or modules in perl that encapsulate
regex calls?
For example, it is encouraged and considered good practice to use standard
c++ libraries for things like arrays and linked lists. For example, you
would use #include<list> in the std namespace to implement a linked list for
your application, rather than rolling one on your own. It is in a sense, a
"black box" for commonly used algorithms and DS for c++.
Does this same analogy hold for Perl with respect to regex?
Hmmm.... in a way. Perl is a higher-level language than C++, and so
there are more things in the core language than in C++. So, Perl has a
basic data type of 'array', which covers pretty much all uses of
arrays/vectors/lists/queues/stacks in C++.
Regexen are part of the language in the same way. The basic unit in
Perl is the 'scalar', which is a polymorphic type: a little like a C
union, except that it is converted between the different
representations as necessary. So if you treat a scalar like a string,
it'll be a string; if you treat it like a number it'll be a number;
etc.
One of the things it can be is a regex, and there is a special
operator '=~' in Perl which means 'match this regex against this
string'. This is something that will perhaps take a little getting
used to coming from C++: Perl is a very operator-rich language, and a
lot of the time it makes more sense to consider your own functions as
operators rather than function calls.
Ben