Wednesday, December 29, 2010

With numbers and strings in Perl

In Perl strings and numbers are called scalars. Scalars, which are over the lifetime of a program does not change as a means of constant or literal. Scalar, which does not change known to be variable. Operators want to do with scaling, for example, add the contents of two variables.

Literal / constant

There are two types of literals:


numeric values, eg 6, 8.5, 11, 17.678, and so on, and
String literals, such as "Hello World".

NumericLiterals can be numbers, eg 6, floating point, for example, 12.5, or scientific notation, for example, 2E10. Strings are a sequence of characters, such as Goodbye Cruel World.

Scalar variables

The data that may change during the life of a program is stored in variables, like $ total. The dollar sign ($) is a type ID, and tells Perl that the variable contains scalar data.

Variable names can contain alphanumeric characters (az, AZ,and 0-9) and underlining and capital letters and lowercase letters.

Expressions and Operators

Perl programs are collections of terms and instructions, the default in the order in which they are executed in the program.

1. #! / Usr / bin / perl-w
2. $ Radius = 10;
3. $ Pi = 3.1415927;
4. Area = pi * $ $ ($ radius ** 2);
$ Sq. 5 Printing;

The equal sign (=) is called the assignment operator. Takes the value on the right side, and puts it inthe variable on the left. An asterisk (*) is the multiplication operator. Two stars with (**) indicate, for power. "

Another example:

1. $ A = "Goodbye";
2. $ B = "cruel world";
3. $ C $ a = $ b;
. 4 print $ c;

The period (.) Concatenate the contents of variable $ a and $ b, and the result is placed in the variable $ c.

No comments:

Post a Comment