📄 the perl weekly journal 1st edition.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-8">
<meta name="GENERATOR" content="Mozilla/4.71 [en] (X11; I; Linux 2.2.14 i686) [Netscape]">
<title>The Perl Weekly Journal By Ankit Fadia</title>
</head>
<body link="#0000FF">
<font face="Comic Sans MS"><font size=-1>____________________________________________________________________</font></font>
<p><b><font face="Comic Sans MS"><font size=-1>The Perl Weekly Journal---By
Ankit Fadia</font></font></b>
<p><font face="Comic Sans MS"><font size=-1>____________________________________________________________________</font></font><font face="Comic Sans MS"><font size=-1></font></font>
<p><tt><font size=-1> ###########
#
###
######### ## #</font></tt>
<br><tt><font size=-1> ############
###
##### ###
##### ### ##</font></tt>
<br><tt><font size=-1> ##### ####
#####
####### ###
### #### ###</font></tt>
<br><tt><font size=-1> ##### ##### #######
######### ###
# #### ####</font></tt>
<br><tt><font size=-1> #### ##### #######
########### ###
### ####</font></tt>
<br><tt><font size=-1> #########
####### ####
#### ###
#######</font></tt>
<br><tt><font size=-1> ###########
##### #####
##### ### ##
#######</font></tt>
<br><tt><font size=-1> ############# ###
## ###### #########
### #### #########</font></tt>
<br><tt><font size=-1> ###### ####
# #### ######## #####
## ###### ### ###</font></tt>
<br><tt><font size=-1> ###### ####
########## #### ####
######### ### #####</font></tt>
<br><tt><font size=-1> ##### ####
########## ### ###
####### #### ######</font></tt>
<br><tt><font size=-1> #############
########## ## ##
##### #### ####</font></tt>
<br><tt><font size=-1> ###########
######## ## ##
### ### ##</font></tt><tt><font size=-1></font></tt>
<p><tt><font size=-1> #######
# # #
#</font></tt>
<br><tt><font size=-1> ########## ##
## ## ##</font></tt>
<br><tt><font size=-1> ### ###
## ## ###
###</font></tt>
<br><tt><font size=-1> ### #
### ### ##### ####
Black Sun Research Facility</font></tt>
<br><tt><font size=-1> ###
## ## ###### ####
http://blacksun.box.sk</font></tt>
<br><tt><font size=-1> ###
## ## ####### ####
ASCII By : cyRu5</font></tt>
<br><tt><font size=-1> # ###
### ### #### #######</font></tt>
<br><tt><font size=-1> ### #### ####
#### ### #####</font></tt>
<br><tt><font size=-1> ########### ###########
## ###</font></tt>
<br><tt><font size=-1> ######### #######
# #</font></tt><font face="Comic Sans MS"><font size=-1></font></font>
<p><font face="Comic Sans MS"><font size=-1>You cannot become a good hacker
unless you have some programming knowledge. Not only for Hacking, Perl
is very much useful for developing security related and also normal but
useful programs.In the Perl Weekly Journal I will be starting from the
basics of Perl and then will move on to some cool advanced stuff.I am assuming
that you do not have any previous programming experience, although a sound
background in C, Basic or JavaScript will help you tremendously.</font></font>
<p><b><font face="Comic Sans MS"><font size=-1>Perl : The Basics</font></font></b>
<p><font face="Comic Sans MS"><font size=-1>Perl was born in 1987 and was
developed by Larry Wall by fusing the Unix utility awk with a system administartion
tool he had developed. Perl's development has been done on the lines of
including all the useful and important aspects of other programming languages
and remove the not so useful aspects. Now Perl is an interpreted language,that
means that the Perl code is run as it is and it is not complied like other
languages.When you first run a Perl program, it is first compiled into
a bytecode, which is then converted into machine instructions.</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now first of all, before you
can start writing your own Perl programs, you need ActivePerl the Perl
Interpreter.You can download ActivePerl for Win32 from:</font></font>
<p><font face="Comic Sans MS"><font size=-1><a href="http://www.activestate.com/ActivePerl">http://www.activestate.com/</a></font></font>
<p><font face="Comic Sans MS"><font size=-1>Follow the links for the latest
build and download it.It is around a 5MB download. After installing ActivePerl
ensure that the file perl.exe is in your path statement.Although ActivePerl
Build 509 sets the path automatically during setup, just make sure that
your path statement contains reference to the file perl.exe by typing "set"
at the command prompt(without quotes), now look for the "PATH" environment
variable and make sure that it contains the line "c:\perl\bin" in that
statement.Normally it would contain this line, but if it doesn' then open
the file c:\autoexec.bat in Notepad and add the following line:</font></font>
<p><font face="Comic Sans MS"><font size=-1>PATH=%PATH%;.;c:\perl\bin</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now save the file and reboot
or update the environment for that session by running the file autoexec.bat
by going to DOS and typing autoexec.bat</font></font>
<p><font face="Comic Sans MS"><font size=-1>Note:Nt users will just have
to update the current system environment by going to</font></font>
<p><font face="Comic Sans MS"><font size=-1>Control Panel > System</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now let's start by the obligatory
Hello World Program.Now to write Perl programs you do not need any special
Perl Text Editor, NotePad would do just fine. So launch Notpad and type
the following:</font></font>
<p><font face="Comic Sans MS"><font size=-1>Print "Hello World\n"; #This
prints Hello World on the Screen</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now save the file by the name
"first.pl". You can replace first by any name of your choice but just remember
that the file should have a .pl extension. Now go the DOS Prompt and then
to the folder in which you had saved the above file and type:</font></font>
<p><font face="Comic Sans MS"><font size=-1>C:\myfiles>first.pl</font></font>
<p><font face="Comic Sans MS"><font size=-1>Note: Replace filename with
the name of the file that you chose while saving.</font></font>
<p><font face="Comic Sans MS"><font size=-1>If the above program does not
work that is you get an error, then check your path statement or try to
write perl filename.pl instead of just filename.pl</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now lets analyse the program,the
word print calls the print function which takes the text from within the
quotes and displays it on the screen.The "\n" symbolises a new line or
the carriage return. Almost all lines in Perl end with a semicolon.</font></font>
<p><b><font face="Comic Sans MS"><font size=-1>Scalars</font></font></b>
<p><font face="Comic Sans MS"><font size=-1>Now let's make the above program
a bit more complex by introducing a scalar.</font></font>
<p><font face="Comic Sans MS"><font size=-1>$scalarvar= 'Hello World\n'
; #the Variable $scalarvar has the value Hello World\n</font></font>
<p><font face="Comic Sans MS"><font size=-1>print "$scalarvar" ; #Prints
value of Variable $scalarvar</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now scalars are declared by
the $ sign followed by the Variable name. The first line feeds the text
with the quotes into the scalar whose name is scalarvar.We know the scalarvar
is a scalar because it is preceeded by the $ sign.</font></font>
<p><font face="Comic Sans MS"><font size=-1>Now you must be wondering why
I have used single quotes in the first line and double in the second. Now
the reason behind this is the fact that Perl performs variable interpolation
within double quotes this means that it replaces the variable name with
the value of the variable. This will become more understandable with the
following examples,</font></font>
<p><font face="Comic Sans MS"><font size=-1>$scalarvar= 'Hello\n' ; # Variable
$scalarvar has the value Hello\n</font></font>
<p><font face="Comic Sans MS"><font size=-1>print '$scalarvar' ; # But
as we use single quotes there is no variable interpolation and</font></font>
<p><font face="Comic Sans MS"><font size=-1>function print prints $scalarvar
on the screen.</font></font>
<p><font face="Comic Sans MS"><font size=-1>Output will be:</font></font>
<p><font face="Comic Sans MS"><font size=-1>$scalarvar</font></font>
<p><font face="Comic Sans MS"><font size=-1>The following is an example
of Variable Interpolation:</font></font>
<p><font face="Comic Sans MS"><font size=-1>$scalarvar= 'Hello' ;</font></font>
<p><font face="Comic Sans MS"><font size=-1>print "$scalarvar" ; # In this
case Variable Interpolation takes place the the Print function</font></font>
<p><font face="Comic Sans MS"><font size=-1>is fed the value of the variable
$scalarvar.</font></font>
<p><font face="Comic Sans MS"><font size=-1>Output will be</font></font>
<p><font face="Comic Sans MS"><font size=-1>Hello</font></font>
<p><font face="Comic Sans MS"><font size=-1>By now the difference between
single quotes and double quotes would have become quite clear.</font></font>
<p><b><font face="Comic Sans MS"><font size=-1>Interacting with User by
getting Input</font></font></b>
<p><font face="Comic Sans MS"><font size=-1>The Diamond Operator i.e </font><font size=+0><
></font><font size=-1> is the Perl equivalent of the C function scanf and
the C++ function cin. It basically grabs input from the user to make a
program interactive.It will become more clear after the following example:</font></font>
<p><font face="Comic Sans MS"><font size=-1>print 'Enter your Name:' ;</font></font>
<p><font face="Comic Sans MS"><font size=-1>$username= </font><font size=+0><>
</font><font size=-1>; #The User will enter a text which will be fed into
the scalar</font></font>
<p><font face="Comic Sans MS"><font size=-1>print 'Hi $username' ;</font></font>
<p><font face="Comic Sans MS"><font size=-1>Output will be:</font></font>
<p><font face="Comic Sans MS"><font size=-1>Enter your Name: Ankit</font></font>
<p><font face="Comic Sans MS"><font size=-1>Hi Ankit</font></font>
<p><font face="Comic Sans MS"><font size=-1>This program will print the
text Enter your Name: on the screen and will wait for user input.</font></font>
<p><font face="Comic Sans MS"><font size=-1>The text entered by the user
will be fed into the scalar $username. Then the program will print Hi followed
by the text entered by the User.</font></font>
<p><b><font face="Comic Sans MS"><font size=-1>chomp( ) and chop( )</font></font></b>
<p><font face="Comic Sans MS"><font size=-1>Now sometimes you need to manipulate
strings and do this there are many functions available which can be used.
So when do you need to use chop( ) and chomp( ) Consider the following
situation厖You need to write a program to print the name and age of the
user which would be input by the User itself. Now consider the following
code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -