You should see:. Perl has a rich library of functions. You can see a list of all the built-in functions on the perlfunc main page. Almost all functions can be given a list of parameters , which are separated by commas. The print function is one of the most frequently used parts of Perl. It takes a list of things to output as its parameters. A Perl program consists of statements , each of which ends with a semicolon. The only thing you need to know is that you never insert commas or spaces into numbers in Perl.
Strings are a bit more complex. A string is a collection of characters in either single or double quotes:. The difference between single quotes and double quotes is that single quotes mean that their contents should be taken literally , while double quotes mean that their contents should be interpreted. Perl has three types of variables: scalars , arrays and hashes. Scalars are single things. This might be a number or a string. You assign a value to a scalar by telling Perl what it equals, like so:.
The conversion happens automatically. This is different from many other languages, where strings and numbers are two separate data types. If you use a double-quoted string, Perl will insert the value of any scalar variables you name in the string.
This is often used to fill in strings on the fly:. Numbers in Perl can be manipulated with the usual mathematical operations: addition, multiplication, division and subtraction. I like the fact that they can make code clearer.
Concatenation and addition are two different things:. Just remember, the plus sign adds numbers and the period puts strings together. Arrays are lists of scalars. Array names begin with. You define arrays by listing their contents in parentheses, separated by commas:. The contents of an array are indexed beginning with 0. Why not 1?
You can also modify it in place, just like any other scalar. This is one less than the number of elements in the array. Each key in a hash has one and only one corresponding value. You define hashes by comma-separated pairs of key and value, like so:.
If you want to see what keys are in a hash, you can use the keys function with the name of the hash. This returns a list containing all of the keys in the hash.
The three types of variables have three separate namespaces. These are useful for explaining what a particular piece of code does, and vital for any piece of code you plan to modify, enhance, fix, or just look at again.
That is to say, comments are vital for all code. Anything in a line of Perl code that follows a sign is a comment. Except, of course, if the sign appears in a string. Loops allow you run a particular piece of code over and over again. This is part of a general concept in programming called flow control. Perl has several different functions that are useful for flow control, the most basic of which is for. When you use the for function, you specify a variable that will be used for the loop index , and a list of values to loop over.
Inside a pair of curly brackets, you put any code you want to run during the loop:. A handy shortcut for defining loops is using.. You can write 1, 2, 3, 4, 5 as Though Perl is not officially an acronym but few people used it as Practical Extraction and Report Language. Perl is extensible. Just to give you a little excitement about Perl, I'm going to give you a small conventional Perl Hello World program, You can try it using Demo link. As mentioned before, Perl is one of the most widely used language over the web.
I'm going to list few of them here:. Perl used to be the most popular web programming language due to its text manipulation capabilities and rapid development cycle.
Perl is widely known as " the duct-tape of the Internet ". Perl's DBI package makes web-database integration easy. This Perl tutorial has been prepared for beginners to help them understand the basic to advanced concepts related to Perl Scripting languages.
Before you start practicing with various types of examples given in this reference, we are making an assumption that you have prior exposure to C programming and Unix Shell. Devi Killada. Harshit Srivastava.
0コメント