Open In App

Perl vs C/C++

Last Updated : 29 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 &#x201cPractical Extraction and Reporting Language&#x201d. Some of the programmers also refer to Perl as the &#x201cPathologically Eclectic Rubbish Lister&#x201d Or &#x201cPractically Everything Really Likable&#x201d. The acronym &#x201cPractical Extraction and Reporting Language&#x201d 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 nowadays for competitive programming. It has imperative, object-oriented and generic programming features. C++ runs on lots of platforms like Windows, Linux, Unix, Mac etc.
Below are some major differences between Perl and c/c++:

Feature Perl 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 process Perl is an interpreted programming language. C++ is a general-purpose object-oriented programming (OOP) language.
Closures Perl can use closures with unreachable private data as objects. C/C++ doesn&#x2019t support closures, where closures can be considered as a function that can be stored as a variable.
File Extension Perl’s scripts are saved using .pl extension. For example perlDocument.pl The.c and .cpp file extension is used to save c and c++ code, respectively. Example: myFile.c and myFile.cpp
Braces In Perl, you must put braces around the “then” part of an if statement. 
Ex: 
if (condition) 
{statement;}
In C/C++ it is not necessary to put braces after if and loops. 
Ex: 
if (condition) 
{statement;}
string declaration Perl 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”;
Comments For 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++




// 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




#!/usr/bin/perl
 
# 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;
}


Output: 
 

The result is 8

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads