Perl5 Basic Concepts and Scalar Commands #1

in #utopian-io7 years ago (edited)

What Will I Learn?

  • Basic Concepts
  • Perl Scalar
  • Numbers and Writing Styles

Requirements

  • Terminal or SSH
  • Linux/Unix Operating System or Linux Hosting

Difficulty

  • Intermediate

Tutorial Contents

Larry Wall "Perl is free!" compiled emphasizes that Perl is both "free" and "open-source." So if you do not have to give permission from anyone to install Perl on your computer or pay someone else's money. If you have Linux installed on your computer, Pel is probably already installed. If not, you can install it immediately with the following command.

curl -L http://xrl.us/installperlnix | bash

Basic Concepts

As you know, UNIX shell programs are made up of UNIX commands sorted into a file. Running this shell program is equivalent to entering and running shell commands in the program files from the keyboard. For example; It's like BAT files in MS-DOS.
The same concept applies to Perl; Perl programs are made up of a set of Perl commands, sorted into a file.
Let's write a short Perl program immediately;

$ cat > sdtyldz
#!/usr/bin/perl
print "Hello Utopian!\n";
^D

$ chmod a+x sdtyldz
$ ./sdtyldz
Hello Utopian!
$

Let's take a look at these commands in order and explain what works.

$ cat > sdtyldz

With this command, you start to create a file with the name "sdtyldz" in your working directory and write the truth entered from the keyboard into the file.

#!/usr/bin/perl

This command reports that the following lines will be interpreted by the perl program in /usr/bin. Without this line; or rather, your Perl program will not work without correctly showing the directory where the Perl program is located. If you do not know which string your Perl program is in, you can learn $ with perl.

print "Hello Utopian!\n";

Yeah! Our first Perl command.
The last "\ n", "Utopian!" after the word you want to make a carriage return says. The next ";" important. Perl specifies the end of the command line.

^D

Control-D. The cat program tells you that the file you are typing from the keyboard is complete, meaning you will not enter more lines.

chmod a+x sdtyldz

Everyone ("a") is authorized to run ("x") for the sdtyldz file.

./sdtyldz

The command that runs the program. You do not have to tell "./" at the beginning. Everyone who is enthusiastic about UNIX knows.

Hello Utopian!

The program worked successfully.

Of course, not every Perl program will be that short; it is also not wise to attempt to write a program using the cat command. I would recommend using an editor such as vi or pico to write Perl code under UNIX. In order to have an idea of the Perl programming language, we start by looking at a Perl program listing usernames in the /etc/passwd file, where user accounts are stored on a UNIX system, with the codes of the system-defined users and their explicit names.

#!/usr/bin/perl
open(PWD,"etc/passwd") or die("/etc/passwd file could not be opened!\n");
while (<PWD>) {
($code, $x1, $x2, $x3, $name) = split(":",$_);
print $code, "-", $name, "\n";
}
close(PWD);

For now I will not go into the details of this program, but I suggest you study carefully the lines for eye familiarity and try to understand what each line does. When examining what the program does, it is especially useful to look into the /etc/passwd file on line 4, where the split() function is used, with the UNIX command more /etc/passwd.

Perl Scalar

As you know, figures, numbers and character sequences are scalar values. Variables whose values they contain or can contain are called scalar functions.

Sayılar
1
3.14159265358979323(π)
1.23e8(1.23 x 10(8))
1.23e-8(1.23 x 10(-8))
-1.23e-8
255
0xff(ff(16) = 255(10))
0xFF(ff(16) = 255(10))
0377(377(8) = 255(10))
$a = 3;$a named scalar variable is assigned numeric value 3.
Strings
"a"
'a'
" "
'123'

A strings of characters with digits 1,2 and 3 in it.

'123ab zyx'
"Hello Utopian!\n"
$a = "Hello Utopian!\n";

We have assigned the character array "Hello Utopian!\n" to the variable $a scalar.

The "\n" symbol is "newline heading"; that is, (Carriage Return, Line Feed). Perl, there are a few other codes with special meaning like "\n".

\nNew Line
\rIndent
\fNew Page
\tTab
\bBackspace
\aBell
\eEscape

The first lesson of our series ends here, in the next lesson we will see Single Quotation and Double Quotation writing styles and Arithmetic Operations. Thank you for reading, respectfully.

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

nice work dude. thank u

Thank you for reading.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @sedatyildiz I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63964.02
ETH 2592.87
USDT 1.00
SBD 2.75