Skip to content
Related Articles

Related Articles

Perl vs C/C++
  • Difficulty Level : Hard
  • Last Updated : 07 May, 2019

Perl is a general purpose, high level interpreted and dynamic programming language. It was developed by Larry Wall, in 1987. There is no official acronym for the Perl, but still, the most used acronym is “Practical Extraction and Reporting Language“. Some of the programmers also refer to Perl as the “Pathologically Eclectic Rubbish Lister” Or “Practically Everything Really Likable“. The acronym “Practical Extraction and Reporting Language” is used widely because Perl was originally developed for the text processing like extracting the required information from a specified text file and for converting the text file into a different form. It supports both procedural and Object-Oriented programming.

C++ is a general purpose programming language and widely used now a days for competitive programming. It has imperative, object-oriented and generic programming features. C++ runs on lots of platform like Windows, Linux, Unix, Mac etc.

Below are some major differences between Perl and c/c++:

Driver function(main())No explicit driver function is required in Perl.C/C++ code requires main() function to execute else code won’t compile.
Compilation processPerl is an interpreted programming language.C++ is a general-purpose object-oriented programming (OOP) language.
ClosuresPerl can use closures with unreachable private data as objects.C/C++ doesn’t support closures where closures can be considered as function that can be stored as a variable.
File ExtensionPerl scripts are saved using .pl extension. For example perlDocument.plThe .c and .cpp file extension is used to save c and c++ code repectively. Example: myFile.c and myFile.cpp
BracesIn Perl, you must put braces around the “then” part of an if statement.
if ( condition )
{ statement; }
In C/C++ it is not necessary to put braces after if and lopps.
if ( condition )
string declarationPerl uses single quotes to declare string.Use of double quotes force an evaluation of what is inside the string.
Example: $x = ‘geeksforgeeks’;
C/C++ uses double quotes to declare a string.
Example: string s =”geeksforgeeks”;
CommentsFor Inline comments, we use # in Perl.
e.g. #Inline-Comment in Perl
C/C++ uses // for Inline comments.
e.g. //Inline-Comment in C/C++.

Program for addition of two numbers in C++ and Perl


// C++ program to add two numbers
#include <stdio.h>
// Function to perform addition
// operation
int add(int x, int y)
    int res = x + y;
    return res;
// Driver Code
int main()
    int choice = 3;
    int choice2 = 5;
    int res = add(choice, choice2);
    printf("The result is %d", res);
    return 0;


# Perl program to add two numbers
$choice = 3;
$choice2 = 5;
$res = add($choice, $choice2);
print "The result is $res";
# Subroutine to perform 
# addition operation
sub add
    ($x, $y) = @_;
    $res = $x + $y;
    return $res


The result is 8
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :