"Don Kim" <> wrote:
> "Ben Morrow" <> wrote in message
> news:bp8cas$hf7$...
> > My recommendation would be: first get the hang of the language,
> > treating a regex as a black box.
>
> 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
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' #