2019年3月4日月曜日

How to run Perl script

I came to know that to start using Perl seemed to be so easy as to build the environment of Perl.

I suppose to keep a record how I built in order that I can remember afterward.



The script we are suppose to run

This time's goal is to run the following script.

Writing the following script on text editor , save it as "hello.pl" .

#! /usr/local/bin/perl

print "HelloWorld!!\n" ;

Confirm the version of Perl

First ,In any directory , run the follow script.
$ perl -v
Then you can see such like message.
The following is the one in my case.
$ perl -v
This is perl 5, version 28, subversion 0 (v5.28.0) built for darwin-thread-multi-2level

Copyright 1987-2018, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Where the Perl is installed

Next we confirm where the Perl is installed.

Running the following command , we can see some message like the following.

The following is my case.
$which perl
/usr/local/bin/perl

Where to put on the script we wrote

Without any your preference , making new directory under the home directory as perl , you had better put the program in there.

If you want to do so, you run the following command , and put the program in there.
$cd
$mkdir perl

Through the Path

we set the environment variable.

Run the following command.

$PATH=~/perl:"$PATH"
In order to confirm whether we could set the environment variable correctly, you had better next command.
$echo PATH
In the message you can see, if you see the sequence of letter you set , you are successful in it.

Modify the Permission

We have to give the authority to perl program.

Run the following command.
$chmod a+x hello.pl

Run!!

Anyway if you doing like above , you can already run the script.

Moving the ~/perl , and run the script.
$cd perl
$hello.pl
You can see
HelloWorld!!



Although I wrote such a article , because I'm not good at English enough, I omitted a lot of what I want to write.
I wish I could write more fluently....
I'm suppose to improve myself more!!