Perl 与Python
Perl 是一种通用、高级解释和动态编程语言。它是由 Larry Wall 在 1987 年开发的。Perl 最初是为文本处理而开发的,例如从指定的文本文件中提取所需的信息并将文本文件转换为不同的形式。 Perl 支持过程和面向对象的编程。 Perl 在语法上与 C 非常相似,对于具有 C、C++ 知识的用户来说很容易。
Python是一种广泛使用的通用高级编程语言。它最初由 Guido van Rossum 于 1991 年设计,由Python Software Foundation 开发。它主要是为了强调代码的可读性而开发的,它的语法允许程序员用更少的代码行来表达概念。
以下是 Perl 和Python之间的一些主要区别:
Feature | Perl | Python |
---|---|---|
Introduction | Perl is a general purpose high level language popular for CGI scripts. Some of the popular projects in Perl are CPanel and Bugzilla. It was initially designed to replace complex shell scripts. | Python is a widely used general-purpose, high level programming language. Due to its rich library and support, it has wide applications in Web Development, Machine Learning, Desktop Applications, etc. |
Whitespaces | Perl does not care about whitespaces. | Python deals with whitespaces and a syntax error generates if whitespaces are not according to Python. |
Focus | Perl accentuates support for common tasks such as report generation and file scanning. | Python accentuates support for common methodologies such as object-oriented programming and data structure design. |
File Extension | The .pl file extension is used to save Perl Scripts. For example myDocument.pl | The .py file extension is used to save Python Scripts. Example: myFile.py |
End of Statement | All statements should end with a semi colon in Perl. | It is not necessary to end the statements with a semi colon in Python as it deals with whitespaces. |
Comments and Documentation | For Inline comments, we use # in Perl. e.g. #Inline-Comment in Perl whereas for documentation we use = and =cut e.g. =Documentation in Perl starts from here and ends here. =cut | Python also uses # for Inline comments. e.g. #Inline-Comment in Python but for documentation we use “”” i.e. Three inverted commas e.g. “””Documentation in Python starts from here and ends here.””” |
Statement Blocks | Perl uses braces to mark the statement blocks. | Python use indentations to mark the statement blocks. |
Datatypes | Some data types contained by Perl are numeric, string, Scalars, Arrays, Hashes. | Some data types contained by Python are numeric, strings, lists, dictionaries, tuples. |