Archived

This topic is now archived and is closed to further replies.

Perl's uses

This topic is 5597 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Have any of you used perl? If so are there any advantages to using it? I was considering on picking up a book to learn perl just because it seems to be in a lot of scripts and programs. I was wondering if its worth it to learn it and what exactly it can do. I checked the perl homepage and it says its a general purpose programming language like c, and some others, but is there any advantage to perl over a general purpose language like c? I''m still a bit confused on the whole perl concept so anyone that can fill me in, please do, it would be greatly appreciated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Hitchhiker90
Have any of you used perl? If so are there any advantages to using it? I was considering on picking up a book to learn perl just because it seems to be in a lot of scripts and programs.

I was wondering if its worth it to learn it and what exactly it can do. I checked the perl homepage and it says its a general purpose programming language like c, and some others, but is there any advantage to perl over a general purpose language like c?

I''m still a bit confused on the whole perl concept so anyone that can fill me in, please do, it would be greatly appreciated.


I''m a Perl nuts, so I''ll try to sum it up. Please keep in mind that Perl is *huge* and extremely versatile (it''s called the Swiss Army Chainsaw), so I can only give a (very) brief overview.

Perl is an interpreted language (that is, it is compiled to bytecode and executed by a virtual machine, just like Java JIT). It is very fast and is the best you can get for string manipulation. It is an amazing tool well suited for a lot of tasks, and often called the "glue language".

Some distinctive characteristics are:

- easy to use: doesn''t require a Ph.D. to start coding something useful,
- doesn''t have primitive types like integers, reals and the such. It uses higher level constructs (scalars, lists/arrays, hash tables and references) in contexts (the scalar "4" will be converted to the string "4" when needed, then converted back to a number if/when required, etc). This can lead to unexpected results if you''re not aware of it,
- has been ported to every platform I''ve heard of,
- easy to expand,
- has the biggest module library on earth (cf http://www.cpan.org),
- free (as in free speech) and free (as in free beer),
- There Is More Than One Way To Do It (TIMTOWTDI) is something you''ll see if you read some Perl discussions: Perl is a very versatile language and as such offers dozens of solutions to most problems.

It is used in for:

- GUI programming (Perl/Tk, Perl/Win32, PerlGtk, bindings for Motif/Lesstif, etc etc),
- multimedia (bindings for SDL, OpenGL, probably also X11, GLX/WGL/AGL/etc, and sound APIs),
- math,
- data mining and analysis,
- database access (Oracle, MySQL, Postresql, probably Informix and Access if you consider Access a DB ),
- Web/CGI (regular CGI, mod_perl, Apache''s Perl API, probably all the other webservers),
- cryptography (most ciphers have implementations in Perl, and bindings exist for a lot of crypto libraries),
- string manipulation, of course: this is where Perl really shines and fears no rival,
- network programming (high level network library as well as lower level, BSD socket-like API),
- file I/O,
- conversion of all kinds (image to ASCII to SGML to XML to LISP, you name it),
- obfuscated programs (cf http://www.samag.com/tpj/obfuscated/) ,
- prototyping all of the above and...
- a lot of other things... Pretty much everything you can do with a computer in user space. You can embed Perl into other languages and embed other languages into Perl.

Perl also has some drawbacks that I must mention in order to be honest:

- all of the above requires modules (cf CPAN): string manipulation is part of Perl''s core, but not the rest,
- it is easy to write unreadable Perl code that even you won''t understand two hours later: you''ll have to be careful if your program has to be maintained at all,
- Perl is context sensitive: it tends to confuse newcomers a lot,
- its interpreter is big and not suited for embedded systems (unless you strip it down or use an embedded Perl),
- threading: Perl can emulate fork() on platforms such as Win32 that don''t have a fork() call, by running another interpreter in a new thread and doing some magic. There is sadly not interface to threads from Perl, unless you build a nasty threaded-Perl and use the Perl 5.0.0 threads,
- probably more things.

Now I guess that you''re interested in game programming. I''ve yet to see any medium to large scale game written in Perl and, given that Perl is interpreted (ie anyone can peek at the source or reverse the bytecode), it''s probably not going to happen. It is, however, extremely useful for tools and prototyping. And of course you could write large scale applications in Perl, as long as you make sure that your code will remain readable.

I must add that the Perl community is very helpful, no matter your level of expertise.

Hope this helps, and sorry about the long speech... I could write books about Perl .

Share this post


Link to post
Share on other sites
On the other hand:

Although it''s not as bad as it used to be, Perl is SLOW. The amount of optimization possible for C/C++ is far better. This doesn''t really matter for many of Perl''s common uses, but don''t waste your time programming any sort of realtime game in it.

Perl''s syntax is hellish. Look at your keyboard... at all the symbols scattered around it, above the number keys, to the right of the keyboard....

PERL USES THEM ALL.

Because of this, and because Perl has so many different "idioms" for doing one thing, perl programs are among the most difficult to read and understand that are out there. Check out the obfuscated perl contest sometime; it is enlightening.

Anyway, Perl is great for people who like to code in Perl. But for making games, you may want to look somewhere  else.



Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Thanks AP! *SMOOCH*

That was pretty helpful info. I don''t think I would be making games with Perl, but I see a lot of programs that use perl so I was just really curious about it and what it could do. I think I will invest in a book, probably one from the O''Reilly series.

Share this post


Link to post
Share on other sites
The O''Reilly book is definately a good choice. For some good examples of what can be done with Perl, you might want to check out my brothers site. He does some serious Perl programming...

Always remember, you''''re unique. Just like everyone else.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
(different AP)

On Slashdot, they had some parodies of the Apple switch ad campaign. One was someone who was a Python developer, switching to Perl. He said, "Well, my spacebar broke, so I couldn''t use Python anymore, so I decided to use Perl. It''s great. I get to use every key on my keyboard, and I know I will always be needed because no one understands my code but me." Things to that effect.

Perl was originally written, IIRC, to replace the hodge-podge of Bash(or maybe just sh), Sed, and Awk. It was the best open-source scripting language at the time, so people added a whole bunch of things onto it that would be useful to script. Perl got immensely popular and several people needed it to run faster, so it got a lot of optimization. It''s not fast enough to do some things, basically just modern games and scientific number crunching. You could theoretically make an arcade style game with it, but doing such long projects is really beyond Perl''s niche.

Perl''s biggest drawbacks are its piecemeal design and its unintelligible and unintuitive syntax. They were mostly C programmers, so they brought over all of C''s operators(I might be wrong), and added a few of their own. All perl variables have a prefix($ or @, and there''s one I''m forgetting), which makes it impossible to be easy on the eyes. Perl has the most advanced syntax for regular expressions, which are used extensively, but which are unintuitive and require quite a long time to learn completely. The majority of the time you use to learn Perl will be learning regexes.

Perl does well in contexts where there''s a single coder or where there are strict and comprehensive coding guidelines. It can do everything, but it does best with text parsing, which makes it suitable for something like cron job(automated tasks) scripting, or for something like web interface creation(I''d use PHP, which is similar, but you get the idea).

I probably wouldn''t use it for anything with a Gui because I like Python better. More people use Perl, though, so Python might not have enough of an ease-of-use improvement to make up for the 10x greater Perl coder population.

Share this post


Link to post
Share on other sites