{"id":1056,"date":"2020-10-30T07:07:05","date_gmt":"2020-10-30T07:07:05","guid":{"rendered":"https:\/\/linuxways.net\/?p=1056"},"modified":"2020-11-06T13:11:43","modified_gmt":"2020-11-06T13:11:43","slug":"how-to-create-and-run-a-perl-script-in-centos-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-create-and-run-a-perl-script-in-centos-8\/","title":{"rendered":"How to create and run a Perl script in CentOS 8"},"content":{"rendered":"<p>Perl programming is a general-purpose language that is mainly developed for text manipulation but, now this is used for a wide range of functions including web development, system administration, network programming, graphical user interface development, and more others.<\/p>\n<p>Perl language is intended to design to be practical rather than beautiful displaying features like minimal, elegant, and tiny. This programming language is complete and efficient. The major features of Perl are easy to use, supports object-oriented (OO) and procedural programming languages, and has built-in support for processing text. The most impressive feature of Perl is that it supports a large collection of third-party modules.<\/p>\n<p>In this article, we will guide you about the Perl installation on CentOS 8. We will also talk about how to create and execute the Perl script on your CentOS system by using the terminal commands.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>You should be logged in from an administrator or root account on your system.<\/p>\n<h2><strong>Install Perl on CentOS 8<\/strong><\/h2>\n<p>Access the terminal window. To do so, click on the \u2018Activities\u2019 and then choose \u2018Terminal\u2019 application from the all left sidebar applications. In the CentOS 8 Linux distribution, the Perl package is already included. By using the following command you can also check the availability of Perl package:<\/p>\n<pre>$ sudo yum info perl<\/pre>\n<p>Now, by typing the following command you will check the installation of Perl packages on your system:<\/p>\n<pre>$ sudo rpm -qa | grep perl<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1097\" height=\"745\" class=\"wp-image-1057\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-605.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-605.png 1097w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-605-300x204.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-605-1024x695.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-605-768x522.png 768w\" sizes=\"auto, (max-width: 1097px) 100vw, 1097px\" \/><\/p>\n<p>On our system the Perl packages are already installed. If Perl is not preinstalled then, first you need to install Perl. By typing the following command with sudo privileges, you can install Perl on CentOS 8:<\/p>\n<pre>$ sudo yum install perl<\/pre>\n<p>Once the Perl configurations are successfully completed on your CentOS 8 system, you can check which version of Perl is installed on your machine:<\/p>\n<pre>$ perl \u2013v<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1094\" height=\"408\" class=\"wp-image-1058\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-606.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-606.png 1094w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-606-300x112.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-606-1024x382.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-606-768x286.png 768w\" sizes=\"auto, (max-width: 1094px) 100vw, 1094px\" \/><\/p>\n<h2><strong>Create and Run Perl Script on CentOS 8<\/strong><\/h2>\n<p>You can run a Perl script by using the following two different methods:<\/p>\n<h3><strong>Method 1:\u00a0 Creating a Perl file<\/strong><\/h3>\n<p>Create a text file by using your text editor and paste the following code in this file:<\/p>\n<pre>#!\/usr\/bin\/perl<\/pre>\n<p>print &#8220;my first Test Perl Script !\\n&#8221;;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1916\" height=\"167\" class=\"wp-image-1059\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607.png 1916w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607-300x26.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607-1024x89.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607-768x67.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-607-1536x134.png 1536w\" sizes=\"auto, (max-width: 1916px) 100vw, 1916px\" \/><\/p>\n<p>Save the above file with the name \u2018testprogram.pl\u2019 on your system. The use of \u2018.pl\u2019 extension with file name represents that this is Perl language Script. In the above program, it will print the text \u2018my first test perl script\u2019 on the terminal while you will execute the script. The \u2018\\n\u2019 is used to move your cursor on the next line of the terminal after displaying the above message. Run the Perl Script by using the following command:<\/p>\n<pre>$ perl testprogram.pl<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1098\" height=\"224\" class=\"wp-image-1060\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-608.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-608.png 1098w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-608-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-608-1024x209.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-608-768x157.png 768w\" sizes=\"auto, (max-width: 1098px) 100vw, 1098px\" \/><\/p>\n<p>Or you can also run the above script by typing the following commands:<\/p>\n<pre>$ chmod +x testprogram.pl<\/pre>\n<pre>$ .\/testprogram.pl<\/pre>\n<p>my first Test Perl Script!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1062\" height=\"126\" class=\"wp-image-1061\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-609.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-609.png 1062w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-609-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-609-1024x121.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-609-768x91.png 768w\" sizes=\"auto, (max-width: 1062px) 100vw, 1062px\" \/><\/p>\n<h3><strong>Method 2: Execute directly using Terminal<\/strong><\/h3>\n<p>You can also execute the Perl command directly by using the terminal.<\/p>\n<p>For example, we want to print the same message on the terminal without creating a text file. In this case, using the following command you can do this:<\/p>\n<pre>$ perl -e \u2018print \u201cmy first Test Perl Script!!\\n\"'<\/pre>\n<p>The following output will print on your terminal after running the above-mentioned command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1096\" height=\"235\" class=\"wp-image-1062\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-610.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-610.png 1096w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-610-300x64.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-610-1024x220.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/10\/word-image-610-768x165.png 768w\" sizes=\"auto, (max-width: 1096px) 100vw, 1096px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Today, we learned about the Perl installation in this article and how to execute a Perl Script on CentOS 8. We have executed various commands on the terminal for running a Perl Script. Moreover, you can also install and configure the necessary Perl modules by using the \u2018yum\u2019 package manager. You can tell us about your queries through the comments.<\/p>","protected":false},"excerpt":{"rendered":"<p>Perl programming is a general-purpose language that is mainly developed for text manipulation but, now this is used for a wide range of functions including web development, system&hellip;<\/p>","protected":false},"author":2,"featured_media":1067,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[38,18],"class_list":["post-1056","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-centos","tag-perl-script"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/1056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=1056"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/1056\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/1067"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=1056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=1056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=1056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}