Perl vs C/C++

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++:



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’t support closures where closures can be considered as function that can be stored as a variable.
File Extension Perl scripts are saved using .pl extension. For example perlDocument.pl The .c and .cpp file extension is used to save c and c++ code repectively. 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 lopps.
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++

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Perl

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

The result is 8


My Personal Notes arrow_drop_up

A fallen star which will rise again

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


3


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.