Perl or Python
Hello Everybody!
Though I would love to use Perl in automation and other scripting tasks, I become a faint-hearted (I admit it) when I have to write Perl CGI for handling Form Data. I am happy, if I can use PHP in order to handle Form Data. Where does Python fit with respect to doing things such as RegEx, Pattern Matching, etc. which Perl does just fine and in a superb way and handling form data and handing them over from one web page to another without having us get tired of writing codes (PHP seems better here)? Thanks in advance for your views! P.S.: One of my Senior Managers has suggested me to go for Python as I am already having good exposures to Perl. |
regex and pattern matching are more or less on the same level, just the syntax differs.
both have a lot of libraries, and a huge amount of info available on the web. So probably python is better (in general), but you need to learn both of them to be able to use them professionally. |
Moderator Response
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
To the OP.
Compare https://en.wikipedia.org/wiki/Anonymous_function#Python to https://en.wikipedia.org/wiki/Anonymous_function#Perl_5 - no limitations in Perl, limitations in Python. Python started supporting closures only from Python 3, which, AFAIK, is not as popular as Python 2. Anyway, since closures in Python is an afterthought, the syntax is ugly. AFAIK Python does not have lexical scoping - see https://en.wikipedia.org/wiki/Scope_...ter_science%29 . Taking all this Python is an underlanguage for me. Whenever I'm looking into a new language, I first of all check presence of the above mentioned features. So you exposure to Perl might be insufficient. Python might be easier WRT writing "C" bindings for it, but with Inline::C Perl module it's not a problem for Perl too. |
Quote:
Some more differences: - Python has nicer object model than Perl. Some syntax differences which I notice the most: - I've grown to love how I can omit parenthesis in Perl in many cases. - I hate indention dictating blocks in Python. - I find $, @ and % too much of a hassle to type. |
Quote:
Here's how Python handles regular expressions and pattern matching: http://docs.python.org/howto/regex.html |
Quote:
Code:
def pow(x): |
Quote:
If you are saying Python has lexical scoping, translate into Python the following: Code:
sergei@amdam2:~/junk> cat -n ./lexical_scoping.pl Quote:
Quote:
Code:
my $n = 10; |
That's block scoping, which Python doesn't have, but it doesn't mean that Python's scoping is not lexical. Here's a code snippet in Python (lexical scoping):
Code:
x = 1 Code:
x=1 Quote:
Code:
n = 10 |
Quote:
Regarding lexical scoping - I suggest to read https://en.wikipedia.org/wiki/Scope_...exical_scoping . |
Quote:
I did read the link you gave, it was quite interesting and useful read, thanks for that. Actually, I took bash example in my previous post from Dynamic Scoping part and rewrote it in Python. If you're trying to tell that Python's scoping is not lexical, I disagree. My given Python and bash examples clearly behave differently, even though they're mostly identical. Also the fact that Python does have closures ("lexical closures" in full, which by definition capture their lexical scope) should take away any doubts. Your Perl example demonstrates that code blocks create their own scope, in Python only functions do that. In fact, the Wikipedia article does mention this (emphasis mine): Quote:
|
Quote:
|
Quote:
Quote:
|
Quote:
|
Quote:
Code:
print 'integer: {}; float: {:.2f}; string: {}'.format(n, f, s) 1) usage of '{...}' - which are items not present in the rest of the code. I mean in Perl for, say, scalar variable I use '$' - be it in '$x = 1;' or in '" ... $x ..."; 2) usage of .format(n, f, s). On the latter. In Perl I write simply as I think: Code:
print "integer: $n; float: $f; string: $s\n"; I mean that the variables appear in the output string in the places they are supposed to be expanded. Nothing is specified in addition. In case of Python: Code:
print 'integer: {}; float: {:.2f}; string: {}'.format(n, f, s) a) I need to specify formats in the string; b) I need to specify variables in 'format(n, f, s)' in correct order - this is inherited from "C" *printf functions. I.e. it sucks in "C" too. Overall, monitoring Python evolution is funny. Originally it was conceived as under-Perl, i.e. some Perl features were intentionally dropped. And now Python 3 catches up with Perl introducing features Perl already head in 1994. |
All times are GMT -5. The time now is 06:20 PM. |