人的心灵本质上是判断性的,所以每当它在众多中选择一件事物时,它就比较物品的各种特征,然后选择一个更接近其要求的物品。
当两种语言在短时间内进入市场时,专业人员会根据语法,功能,易用性和支持的环境开始对它们进行比较。Perl比Python旧,但没有那么多。
Perl的开发是为了处理与UNIX机器上当时报告内容相关的文本过程,而Python则是编程语言ABC的后续结果。
这两种语言都有以下共同特征:
1.两者都是针对UNIX机器开发的。
2.两者都被解释为未编译。
3.两者都是OO(面向对象),但是当我们谈论OOP时,Python领先于Perl。
4.两者都是开源的,您可以根据需要进行修改。
他们都通过互联网获得了广泛的社区支持。
Perl与Python之间的前6位比较
1. 命令行
Perl
如果您是Window用户,那么在安装Perl之后,您可以打开一个如下所示的公共窗口
C:> perl -e <你可以在这里编写Perl代码>
如果你是Linux或Unix用户,那么你可以得到像这样的东西
$ perl -e <perl code goes here>。
Python
对于窗口用户安装Python后,代码提示将如下所示从python脚本文件运行python代码。
C:> python script.py
对于Linux用户,相同的提示将如下所示
$ python script.py
2. 空白字符
Perl并不关心空格。
Python处理空格,如果空格不符合Python,则会出现语法错误。
3. 评论
以#开头的声明将被视为评论。
#这是Perl中的内联注释
我们使用的Perl文档
=和=切
例如:
这是对Perl的评论
但你也可以用它作为文档
=切
#这是Python中的内联注释
三个倒置的逗号也可以用作文档或注释
msgstr“”“这是用于python的,可以在文档和注释中使用”“”
4. 声明结束
Perl声明以;结尾;
在Python中; 不要求结束
程序声明,因为它处理空格。
5. 正则表达式
Perl是该语言的一部分,它使文本处理变得简单和简短。 虽然Python需要处理正则表达式的函数和方法
6. 编写代码的方式
Perl提供了以不同风格编写相同代码的自由。
例如,使用if语句您可以通过以下方式声明If语句:
if($ var1!= $ var2){print“两者不相同\ n”; }
除非($ var1 == $ var2){print“两者相同\ n”; } ----------------
除非$ var1 == $ var2,否则打印“两者都相同\ n”;
打印“两者不相同\ n”如果$ var1!= $ var2; ----------------
$ var1 == $ var2 || 打印“两者相同\ n”;
$ var1!= $ var2或print“两者不相同\ n”;
语句以大括号{}开始和结束if(($ var1!= $ var2){print“hello world”;}
然而,Python并不相信这样,并强迫以自己的Pythonic方式编写代码。
对于if语句,您可以得到以下内容:
if(var1 == var2):
打印(“两者相同”)
Python使用缩进相同
Differences Between Perl vs Python
The human mind is judgmental by nature so whenever it gets to choose one thing among many then it compares various features of items and then chooses one which is closer to its requirement.
When two languages come in the market in short interval of time then professionals start comparing them on the basis of syntax, feature, ease of use and environment supported. Perl is older than Python but not so much.
Perl was developed to deal with text process that is related to reporting stuff at that time on UNIX machine while Python was a result of a successor of programming language ABC.
Both the languages have following features in common:
1. Both were developed to target UNIX machine.
2. Both are interpreted not compiled.
3. Both are OO (Object oriented) but Python is ahead of Perl when we talk about OOPs.
4. Both are open source in nature and you can modify it according to your need.
5. Both have vast community support over the internet.
The top 6 comparison between Perl vs Python
1. Command Line
Perl
If you are a Window user then after installing Perl,you can open a common window which will look like thisC:>perl -e <you can write Perl code here>If you are Linux or Unix user then you can get the same thing like this$perl -e <perl code goes here>.
Python
For window user after installing Python then code prompt will look like this to run the python code from python script file.C: >python script.pyFor Linux user, the same prompt will look like this$python script.py
2. Whitespaces
Perl does not care about whitespaces.
Python deals with whitespaces and will give syntax error if whitespaces are not according to Python.
3. Comment
Statement started with # will be considered as comment.
# This is an Inline comment in Perlfor documentation in Perl we use=and =cutFor example:= This is a comment for Perlbut you can use it as documentation also=cut
#This is an inline comment in PythonThree inverted comma is also can be used as documentation or comment
“”” This is for python and can be used in documentation as well as in comment “””
4. Statement End
In Perl Statement ends with;
While in Python; is not required to endthe program statement as it deals with whitespaces.
5. Regular Expression
Perl is a part of the language which makes text processing easy and short. While Python need to deal with functions and method for regex
6. Way of writing code
Perl provides freedom to write same code in different style.For example take if statement You can declare If statement in following ways:if ($var1 != $var2) { print “Both are not same\n”; }unless ($var1 == $var2) { print “Both are same\n”; }———————————————–print “Both are same\n” unless $var1 == $var2 ;print “Both are not same\n” if $var1 != $var2 ;———————————————–$var1 == $var2 || print “Both are same\n”;$var1 != $var2 or print “Both are not same\n”;Statement starts and ends with curly braces { }if (($var1 != $var2) {print “hello world”;}
Nevertheless Python do not believe as such and force to write code in its own Pythonic way.For if statement you get things like this:if(var1 == var2) :print(“Both are same”)Python uses indentation for the same