Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Learn Regex or Perl Frist? (http://www.velocityreviews.com/forums/t883686-learn-regex-or-perl-frist.html)

Don Kim 11-16-2003 05:26 PM

Learn Regex or Perl Frist?
 
I'm looking to learn perl. Comming from a c++ background, I'm not finding
it very hard to learn, except for getting used to deciphering terse regex
expressions.

Curious, is it better to learn regex first, from say a book like "Mastering
Regular Expressions" by Friedl, then learn perl?

Thx.

Don



Ben Morrow 11-16-2003 05:32 PM

Re: Learn Regex or Perl Frist?
 

"Don Kim" <nihilistcoder@yahoo.com> wrote:
> I'm looking to learn perl. Comming from a c++ background, I'm not finding
> it very hard to learn, except for getting used to deciphering terse regex
> expressions.
>
> Curious, is it better to learn regex first, from say a book like "Mastering
> Regular Expressions" by Friedl, then learn perl?


My recommendation would be: first get the hang of the language,
treating a regex as a black box. When you find that you need to
understand or construct one yourself, read perldoc perlretut or
chapter 5 of the Camel ('Programming Perl', L. Wall, T. Christiansen &
J. Orwant; O'Reilly).

Ben

--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else * ben@morrow.me.uk

James Willmore 11-16-2003 06:54 PM

Re: Learn Regex or Perl Frist?
 
On Sun, 16 Nov 2003 09:26:11 -0800
"Don Kim" <nihilistcoder@yahoo.com> wrote:
> I'm looking to learn perl. Comming from a c++ background, I'm not
> finding it very hard to learn, except for getting used to
> deciphering terse regex expressions.
>
> Curious, is it better to learn regex first, from say a book like
> "Mastering Regular Expressions" by Friedl, then learn perl?


If you want to practice with regular expressions in a C++ environment,
then might I suggest pcre++ (http://www.daemon.de/en/software/pcre/).
It's Perl Compatible Regular Expressions in C++. This way, you can
learn Perl Compatible Regular Expressions in C++ :-)

If you want to learn Perl, start using the 'perldoc' utility first
(type 'perldoc perldoc' and 'perldoc perl' at the command line to
start). Then, if you want a more extensive look at the language,
you'll a least know what to look for in a book you purchase. Why
throw down $30+ if you don't have to :-)

Being an owner of the book mentioned I can say this - unless you're
going to be doing what the author has done with regular expressions,
save your money. If you *must* have a book, get the pocket book by
the same title ($12(?) versus $30(?) for the full book).

That's my $0.02

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Nobody said computers were going to be polite.


Don Kim 11-16-2003 07:26 PM

Re: Learn Regex or Perl Frist?
 
"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bp8cas$hf7$1@wisteria.csv.warwick.ac.uk...
> 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?

Thanks for your time.

Don





Don Kim 11-16-2003 07:30 PM

Re: Learn Regex or Perl Frist?
 
"James Willmore" <jwillmore@remove.adelphia.net> wrote in message
news:20031116135434.0db71dcf.jwillmore@remove.adel phia.net...
> If you want to practice with regular expressions in a C++ environment,
> then might I suggest pcre++ (http://www.daemon.de/en/software/pcre/).
> It's Perl Compatible Regular Expressions in C++. This way, you can
> learn Perl Compatible Regular Expressions in C++ :-)


Thanks! I also looked at the regex library in boost and one called "Greta"
from a guy in microsoft. How does this compare to those? Assuming you've
looked at them.

> Being an owner of the book mentioned I can say this - unless you're
> going to be doing what the author has done with regular expressions,
> save your money. If you *must* have a book, get the pocket book by
> the same title ($12(?) versus $30(?) for the full book).


Actually, I already purchased the book, but I got it used for $12 so it was
worth it. I hear you though, I'm sick of buying books only to find it
wasn't useful to me. :-(

Don



Jürgen Exner 11-16-2003 07:40 PM

Re: Learn Regex or Perl Frist?
 
Don Kim wrote:
> I'm looking to learn perl. Comming from a c++ background, I'm not
> finding it very hard to learn, except for getting used to deciphering
> terse regex expressions.
>
> Curious, is it better to learn regex first, from say a book like
> "Mastering Regular Expressions" by Friedl, then learn perl?


The one has little to do with the other. Perl offers also nice arithmetic
functions.

Depending on what you want to do with Perl you may need arithmetic functions
or you may need REs.
The main difference is that you learned about arithmetic in school, but you
didn't learn about REs in school. Therefore plus and minus seem to be more
natural to you.

Make up your mind what kind of programs you want to write. If all you ever
do is numerical calculations then you don't need any REs. If you are going
to write a lot of text processing programs then sooner or later you will
want to learn about REs and you automatically will.

jue




Tad McClellan 11-16-2003 07:48 PM

Re: Learn Regex or Perl Frist?
 
Don Kim <nihilistcoder@yahoo.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:bp8cas$hf7$1@wisteria.csv.warwick.ac.uk...
>> 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?



Sure, but that isn't (I think) what Ben meant.

He meant don't _try_ to understand the terse regexs for now, just
use them.

(and be sure to reverse that when you are writing production code. :-)

You can do lots of useful stuff while learning Perl even if your
programs don't need or use regexs.

(more accurately: if they don't use one of the pattern matching
operators. "Regexes" don't _do_ anything, "operators" do things).


> Does this same analogy hold for Perl with respect to regex?



You can write modules (Perlspeak for "libraries") to do
just about anything, including pattern matching. See:

http://search.cpan.org/search?query=regex&mode=all

and

http://search.cpan.org/~abigail/Regexp-Common-2.113/


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Ben Morrow 11-16-2003 09:10 PM

Re: Learn Regex or Perl Frist?
 

"Don Kim" <nihilistcoder@yahoo.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:bp8cas$hf7$1@wisteria.csv.warwick.ac.uk...
> > 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/' # ben@morrow.me.uk

James Willmore 11-17-2003 01:03 AM

Re: Learn Regex or Perl Frist?
 
On Sun, 16 Nov 2003 11:30:58 -0800
"Don Kim" <nihilistcoder@yahoo.com> wrote:
> "James Willmore" <jwillmore@remove.adelphia.net> wrote in message
> news:20031116135434.0db71dcf.jwillmore@remove.adel phia.net...

<snip>
> Thanks! I also looked at the regex library in boost and one called
> "Greta" from a guy in microsoft. How does this compare to those?
> Assuming you've looked at them.


I looked over pcre++. I've done more in Perl than C++. The
construction of a regex in pcre++ and Perl are about the same. I
can't speak of performance. I didn't run benchmarks, so I'm not 100%
sure.

<snip>
> Actually, I already purchased the book, but I got it used for $12 so
> it was worth it. I hear you though, I'm sick of buying books only
> to find it wasn't useful to me. :-(


At least it wasn't full boat ;-)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Deliberation, n.: The act of examining one's bread to determine
which side it is buttered on. -- Ambrose Bierce, "The Devil's
Dictionary"

John W. Krahn 11-17-2003 07:32 AM

Re: Learn Regex or Perl Frist?
 
Ben Morrow wrote:
>
> 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'.


Actually =~ is the binding operator and if used with tr/// there is no
regex involved.


John
--
use Perl;
program
fulfillment


All times are GMT. The time now is 04:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.