Archived

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

gandolf1212

Perl under rated?

Recommended Posts

gandolf1212    100
Well, I decided to learn Perl for cgi scripts which it seems most commonly used for. After working a little bit with it though it seems like it could prove a useful language for anything. I''ve done C++ for a few years now but after a few days with Perl i''m about ready to switch over. Reasons why you ask? + String management! God I love this one! No more String class or char *word or char word[515]. Not only does it it have all the operators overloaded for strings it comes with functions like split. Plus it resizes your string to hold any sized word. + File IO is very easy + No declarations, variables are made when there used + No types, just like java-script + 2 array types! Your standard subscript array and an associative array which lets you (among other things) use words for subscripts. Great for CGI. + Condition false controls. Like unless and until. + The for each loop which is made to go through array''s. + Cool array features like being able to find out how big it is real easy and commands like pop and push and sort. + Pretty much everything else that is in a high level language. Plus it can be script or binary. + Condition false controls. Like unless and until. + The foreach loop which is made to go through array''s. + Cool array features like being able to findout how big it is real easy and commands like pop and push and sort. + Pretty much everything else thats in a high level language. Plus it can be script or binary. Soo.. My question is why don''t more people use and like Perl. I have heard that the preformance is a little less than C++ or Pascal but i''m not sure. Is there somthing major that Perl lacks or falls short with? I just want to make sure Perl really is as good as C++. Hate to find out after 9 months or doing Perl it has a hard coded limit of 5 fps or something =) Thanks alot for any input.

Share this post


Link to post
Share on other sites
Colin Jeanne    1114
quote:
Original post by gandolf1212
+ String management! God I love this one! No more String class or char *word or char word[515]. Not only does it it have all the operators overloaded for strings it comes with functions like split. Plus it resizes your string to hold any sized word.

+ The for each loop which is made to go through array''s.

+ Cool array features like being able to find out how big it is real easy and commands like pop and push and sort.

+ The foreach loop which is made to go through array''s.



I assume you dont like the STL



I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm

Share this post


Link to post
Share on other sites
Bad Monkey    145
I have absolutely no objection to people writing in Perl, but I personally think the syntax and readability of it is atrocious... some programs I have seen are like trying to read a Chinese restaurant menu that has been encrypted in triple-DES

To each his own I guess...

Share this post


Link to post
Share on other sites
andrew_j_w    122
You might want to take a look at Python (www.python.org), it has all the power of C++ with the benifits of perl and a readable syntax.

I use it all the time for just about everything. There are even OpenGL binds for it so you can do 3d graphics work with it.

Andrew

Share this post


Link to post
Share on other sites
coderx75    435
Ummm... okay, Perl = Games? The syntax alone makes it useless for anything larger than a CGI script

It''s been a few years since I''ve used it and from what I understand, it''s evolved but the syntax seems to have gotten worse.

If you''re lookin'' for advice, I''d strongly suggest stickin'' with C++. Invader X mentioned STL. Look into it a bit. G'' luck!

- Jay

"Strictly speaking, there is no need to teach the student, because the student himself is Buddha, even though he may not be aware of it." - Shunryu Suzuki

Get Tranced!

Share this post


Link to post
Share on other sites
Dean Harding    546
Perl''s pretty good, it''s got quite a rich syntax (e.g. native support for hash tables, and regular expressions, like you said) which means you can do some things in one line which may take tens or hundreds of lines in C++, but for that same reason, people tend to get a bit carried away trying to fit things in as few lines as possible

If you can resist that temptation, perl is very good for a lot of things, though it was really only meant for short scripts which have lots of string manipulation and so on. For other things, it''s not going to be as good (due to a lack of libraries, mainly)


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
Dark Rain    157
I'm not saying it's as easy as Perl but the STL string class is pretty powerful, along with containers, stl algo ,stringsteam etc.

[edited by - Dark Rain on June 9, 2002 6:08:18 AM]

Share this post


Link to post
Share on other sites
thona    100
OH MY GOD - sure that you really have done C++ programming on anything more than a small scale?

quote:
Original post by gandolf1212
Well, I decided to learn Perl for cgi scripts which it seems most commonly used for. After working a little bit with it though it seems like it could prove a useful language for anything. I''ve done C++ for a few years now but after a few days with Perl i''m about ready to switch over. Reasons why you ask?

+ String management! God I love this one! No more String class or char *word or char word[515]. Not only does it it have all the operators overloaded for strings it comes with functions like split. Plus it resizes your string to hold any sized word.


Not exactly a perl specific thing, you know. Actually most high level languages can do this. Oh, and when you write a complex 3d game, you will definitly make most of your work in this area, right? And look at the C++ classes for stings - they are pretty good, too. C++ is more than just the syntax.

quote:

+ File IO is very easy



As is it in most other languages, and even in C++.

quote:

+ No declarations, variables are made when there used



Yea, right, writing shitty code. means that if you mistype a variable name, then the program misbehaves instead of the compiler complaining.

quote:

+ No types, just like java-script



Yea, right - writing shitty code is an advantage. Strong typed variables help you catch errors in anything more complex than a simple CGI script - by having the compiler throw an error.

quote:

+ 2 array types! Your standard subscript array and an associative array which lets you (among other things) use words for subscripts. Great for CGI.



Look up on STL and learn C++. Please.

quote:

+ Condition false controls. Like unless and until.

+ The for each loop which is made to go through array''s.



Well. foreach is pretty nice and shugar (though I LOIVE this when making my C# work - whow :-)

quote:

+ Cool array features like being able to find out how big it is real easy and commands like pop and push and sort.



Now, lets clarify this - you DO know C++? I mean, you ever heard of STL? Just to make sure - oh, you said so. Well...

quote:

+ Pretty much everything else that is in a high level language. Plus it can be script or binary.



And you can make such wonderfull complex systems with it - I mean, things like a control system with 15.000 db transactions a second. Oh, sorry - ou just want to write gaems not using up all CPU or small CGI scripts.

quote:

+ Condition false controls. Like unless and until.

+ The foreach loop which is made to go through array''s.

+ Cool array features like being able to findout how big it is real easy and commands like pop and push and sort.

+ Pretty much everything else thats in a high level language. Plus it can be script or binary.



Repetition - running out of arguments?

quote:

Soo.. My question is why don''t more people use and like Perl. I have heard that the preformance is a little less than C++ or Pascal but i''m not sure. Is there somthing major that Perl lacks or falls short with? I just want to make sure Perl really is as good as C++. Hate to find out after 9 months or doing Perl it has a hard coded limit of 5 fps or something =) Thanks alot for any input.


Well,
(a) most game developers want every bit of performance. I can NOT understand this - a little less speed in the core language will not make a huge difference. 10% loss are definitly acceptable IMHO (dont forget - when you go graphics it is hardware accelerated anyway). Thats why I opt for C#, but thats another story.

PRACTICALLY all API is written in C++ - means that you easily get C++ header files for OpenGL, DirectX etc., but no perl implementation. And then, use a tool for what it is done - Perl is done for analyzing logfiles (RL in Perl: Reporting Language).

Frankly, you expose quite some "non-knowledge" about C++ - like not knowing STL at all. I am not sure I would call you even an apprentice C++ developer.

THONA
[
Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
http://www.thona-consulting.com/
]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by gandolf1212
+ Condition false controls. Like unless and until.


#define unless(x) if( !(x) )
#define until(x) while( !(x) )

There. There''s your unless and until.

Share this post


Link to post
Share on other sites
Neophyte    595
Perl is definitely a language that should be on most people''s list of known languages. But the important thing to remember is "the right tool for the right job". Perl is excellent for things like text-parsing, simple file-handling, and to some extent web-programming, although I prefer Java servlets and PHP for anything more than very simple CGI-scripts myself.

As has been pointed out, Perl isn''t exactly the fastest language you can use, but when throwing together something like an apache-log analyzer, I wouldn''t even consider doing that in C/C++.

When it comes to the complaints about horrible syntax, that is more a result of the fact that perl is very much used for text-parsing, and reg-exps are really the best way to go for that, often leading to expressions like
$var ~= s/(.*?)\\(.*)/($2);
(Which is not by far a bad expression compared to other you regularily see bandied about perl-scripts).
And although these kinds of expressions can be difficult to figure out if you''re not used to reading regexps, but can lead to very terse code (which most perl-hackers love even more than C-programmers).

Anyway, at the risk of overly repeating myself, "right tool for the right job".

-Neophyte

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com

Share this post


Link to post
Share on other sites
OrangyTang    1298
quote:
Original post by Bad Monkey
I personally think the syntax and readability of it is atrocious... some programs I have seen are like trying to read a Chinese restaurant menu...


heh, you obviously havent tried K have you...

Perl''s pretty neat for text manipulation, but the lack of any strong typing really annoys me.

Share this post


Link to post
Share on other sites
Perl is a very powerful, AND useful, language, but not much used for graphics. It's one of my languages of choice, I use it at work for web-applications, when I do graphics programming at home (for fun) I mainly use c/c++ but use Perl to generate/convert vertex data and such.

Today Perl is mostly used for system administration and web-related programs (not only CGI). Some of these are small scripts of 10-20 lines, but there's big object-oriented packages out there in the world (I know, I've been working on 2 of them). The object-oriented features are sort of bolted on, but they ARE powerful. And you can rewrite them (in Perl) if you fancy, Damian Conways "Object Oriented Perl" has a lot of neat information if you're interested.

You can find a lot of bad/unlucid written Perl code, but thats true for every other widely used language. Some people hate the syntax, it can be a bit wierd with "open FILE or die" and stuff like that, but on the other hand, think of the first time you saw C: "void" this and that, and "*whatnot = something".

For Game Programming I think Perl would be most useful if embedded in an engine written in c++. I've been looking for examples on the web, but have found that python is much more used in this area. For example, the Crystalspace engine has support for embedded python, with source-code. Mind you, they use a generic scripting interface called SWIG, so maybe their code could easily be converted to perl.

Python-programmers love to dis perl, so I've always disliked python a bit for that reason :-) , but seriously, python seems to be a decent language, but in a lot of small ways more different from c/c++ than perl (not using braces to delimit code-blocks, no semicolons at endline, indention for structure) so I think it'll be difficult to switch quickly (ie a couple of secs) between code written in python and c++. But apparently a lot of other people have coped with that :-) .

Some comments on your reasons for liking perl:

+ No declarations, variables are made when there used
Thats NOT a good thing, misspelled variables won't get caught. Add "use strict;" at the top of your program. Declare all variables with "my".

+ No types, just like java-script
Note that there ARE types in perl, it's just that a normal scalar variable can be assigned a value of any type. Perl is what is called a weakly typed language or maybe its weakly type-checked language, like python, ruby and a host of others, including, I think, smalltalk. Note that this is both a boon and a blessing. If you call a method on an object (eg $obj->method) there's no check at compile-time if $obj is a type which has "method()" defined, like there is in c++ or java, which can make inheritance much easier. However, at run-time the program will throw an exception (die actually) if it can't find a "sub method" in $obj's namespace, so you better be sure that this won't happen, OR add code to handle the exception (eval {...}; if ($@) {...} ).

+ Condition false controls. Like unless and until.
Actually I try to avoid these in my code but YMMV.

+ Cool array features like being able to find out how big it is real easy and commands like pop and push and sort.
Have you checked out Map and Grep? Perl is array-heaven :-)

+ Pretty much everything else that is in a high level language. Plus it can be script or binary.
??? I've seen .EXE-converters for windows, but I don't think they actually make the program any faster, if thats what you mean.

Another Poster said something about "lack of libraries". Try to take a look at www.cpan.org.



---------
"It's always useful when you face an enemy prepared to die for his country. That means both of you have exactly the same aim in mind." -Terry Pratchett


[edited by - deformed rabbit on June 9, 2002 9:38:50 AM]

Share this post


Link to post
Share on other sites
pwd    122
LOL. That was a troll, right ?

Just think, you could shape your code like one of the characters from your game.

Share this post


Link to post
Share on other sites
gandolf1212    100
Thona, I know about the stl and use it in almost every program I write. However, Perl''s handling of many things is alot more natual feeling than C++''s. Sure I could include the libararies, declare a string class and then use that but with Perl all it takes is $word = "word"; Pretty much the same thing holds true for vector. I will however agree with some of the stuff said about Perl syntax. To many symbols...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
So you are to lazy to include a library...oh dear...

Share this post


Link to post
Share on other sites
Dark Rain    157
"So you are to lazy to include a library...oh dear... "

Dont be so harsh, #include <string> is pretty long to write and what about that horribly complicated std:: or worse an STD namespace!

Share this post


Link to post
Share on other sites