LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python or Perl (https://www.linuxquestions.org/questions/programming-9/python-or-perl-406345/)

drdroid 01-21-2006 07:40 PM

Python or Perl
 
I have some pretty good c++, basic, fortran, javascript/html under my belt. I want to learn linux scripting that can eventually be used for networking, systems anything. What do you suggest? And by your opinion, which is best? Perl or Python?

johnMG 01-22-2006 01:19 AM

If you search the forum, you'll find lots of threads about this very topic.

Jack Deth 10-25-2006 10:00 AM

Quote:

Originally Posted by drdroid
I have some pretty good c++, basic, fortran, javascript/html under my belt. I want to learn linux scripting that can eventually be used for networking, systems anything. What do you suggest? And by your opinion, which is best? Perl or Python?

You know alot of people try out the WebAPP Script which is perl based, and from there I have seen them get into perl big time seeing how its one of the easiest to learn but hardest to master languages out there...

check it out at http://www.web-app.net and see if it does what you want... can be used for web portals or internal portals...

bigearsbilly 10-25-2006 10:26 AM

answer yes,
they are both lovely languages,
see the big post on this very forum (lots of bored people out there)

ghostdog74 10-25-2006 06:33 PM

if you have time, i would suggest learn both. A lot depends on your taste/preferences, as well as the problem to be solved at hand.
Personally, i use Python alot. My "taste" is i like its readability and i don't like those extra ";{}" in most other languages. And i also don't care about speed as my problems to be solved does not require speed. Like i said, these are my own preferences, so you have to find your own.

bigearsbilly 10-26-2006 02:12 AM

good advice ghostdog.

python slow?
at the risk of sort of hijacking the thread how do you find python speedwise?

I use perl a lot and have found it almost as fast as a bit of C code
for text and file processing type stuff (bulk of my work). So much so
that i don't bother with C anymore.

I did a quick test python v. perl, just slurping /usr/dict/words, randomising and printing out and found python slightly faster, which
surprised me.

slantoflight 10-26-2006 03:29 AM

Perl has some of these bizzare, secret handshakes almost.

Jaqui 10-26-2006 08:30 AM

as ghostdog said, it's personal preference that determines which is best.

perl, fantastic tools for text manipulation.
python, not so much with the text.
[ python is far younger and does't have the same library availablity as perl ]

but any language is a valid option for use as a bash script, including compiled languages. You have c++ skills, write your script as a cli c++ app and compile it, then you can call it like any other script.
heck, even php can be used for a bash script.


bigbearsbilly,
I bet python is faster because of the number of modules you have installed for perl :p

The more capable a language is the slower it will perform, simply because the interpreter has to scan a larger database of available functions to make sure it has the ones needed for the script. This is why interpreted languages are slower in performance than compiled languages usually.
[ use c or c++ to go through your little test, I don't think they will be as fast as either perl or python ]

I would use whichever language I know has the best toolset available for the task that needs to be accomplished. This means any particular script can be written in any language I'm capable of writing in, not just one language only. This has the benefit of using the best tool for any particular job, instead of a single multitool for every job.

xhi 10-26-2006 08:52 AM

Quote:

Originally Posted by drdroid
I have some pretty good c++, basic, fortran, javascript/html under my belt. I want to learn linux scripting that can eventually be used for networking, systems anything. What do you suggest? And by your opinion, which is best? Perl or Python?

imo, perl. but i have barely used python (does hello world count?).. so i guess im not qualified to answer this question at all.. im leaving.. :D

(seriously though, i find Perl to be lots of fun and would definately reccommend learning it sometime.. whether you should do that before or after python i cant say..)

R00ts 10-26-2006 09:19 AM

I've been writing Perl scripts in the last year and a half to do some fairly complex tasks. But now, I am going to re-teach myself Python and switch to that language because I am fed up with Perl. Writing Perl code has to be one of the most frusterating programming tasks I've ever done. I just think that syntatically speaking, the language is poorly defined (I know this is intentional, but still) and reading Perl code is not intuitive so I often have no clue what a snippet of code does. The only thing I dislike about Python is the forced indentation (I feel that's not the job of a programming language), but its much more sane than Perl IMHO. :)

ghostdog74 10-26-2006 08:49 PM

Quote:

Originally Posted by R00ts
The only thing I dislike about Python is the forced indentation (I feel that's not the job of a programming language), but its much more sane than Perl IMHO. :)

Welcome to Python :)
and you shouldn't have to dislike it because of the indentation. After a while you will get used to it. Sometimes when i switch back to writing Perl or other languages, my fingers automatically will press the tab key to indent every time i reach a new line..haha

chrism01 10-27-2006 02:59 AM

Interpreted langs a much slower because they re-compile each statemnt on the fly, every time it is used.
Also, in bash you are often calling other progs eg sed, awk etc... This means creating a new process each time.
Compiled langs already have everything they need in binary format before they start.
Perl is more of an 'executable environment' (see http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html )
As mentioned in another thread, it's pretty quick, say 90 % speed of C.

bigearsbilly 10-27-2006 04:18 AM

the indentation is a fabulous idea. simple and saves typing braces and such
;)

mrcheeks 10-27-2006 06:43 AM

I have written a Java application which is using connecting to OpenOffice to perform some macro and export the document as Docbook XML(may be one day Open Source).

The problem is that I have a lot of code which I have not time to refractor or improve a lot. It is difficult for a novice/junior programmer to understand my code(SpringFramework, Java Reflection, Interfaces, MVC, Swing, XML, XSLT). I used advanced concepts and patterns to design and program the application.

I took a look at Python, Ruby and Perl. I decided to evaluate Python. I can code faster and performance is not really an issue.
All I need to be able to do is to make the application evolve and maintain it.
If I have no time, then someone else should be able to work on the application without spending time training, reading or asking me all kind of questions.
I learn basics of Python in 4 days and I have almost the same application with less lines of code. Using the MVC pattern is not that difficult in Python. I didn't take a look at data bindings framework for Python(class model --> GUI). I don't intend to write such a framework for now...
It seems that Python will fullfill my needs.
------
Pros
------
* Lots of libraries
* Python is simpler than C, C++, perl, Java and some other languages.
* Clean code(indentation required)
* Object orient aspects(classes, packages, inheritance). With zope interfaces it is better.
* IDE support
* GUI designer support for wxWidgets, Gtk and Qt using wxglade, glade, xcred or any other commercial tool. The tools support XML resources or they can generate Python Code directly. I prefer to have the XML using XrCed and bind the GUI controls to events.
* Can do console programs, gui(wxpython, tkinter, pygtk, pyQt, fxpy, etc.) or web programs(Django, turbogears, etc.)
* Lots of libraries available
------
Cons
------
* Slower than Java
* Require "an abusive use" of self for classes' members
* Not that many good IDES except SPE, DrPython or PyScripter
* You often have to check the version of your libraries all the time to see if there are compatible with your version of python or any other dependencies that your program requires
* Python is not that used in the entreprise compared to Java, C#, Perl in that order.
* I miss Java Web Start because I release often and many users use my application.
I could use python twisted and write an updater...

ghostdog74 10-27-2006 07:33 AM

Quote:

Originally Posted by mrcheeks
* Slower than Java

May i know what are you comparing the speed against?
If its development time, then defintely Java is slower.:)


All times are GMT -5. The time now is 06:13 AM.