Monday, November 15, 2010

PERL – (Cont.)

Scalar Data and Scalar Variables:

v Unlike the languages like C and Java which has distinct type of integers, characters, floating-point numbers which has strict rules, Perl has a flexible data types.

v It distinguishes only two type/kind of data.

- Scalar Data – Numbers and Strings of Characters

- List Data – Arrays.

Numbers:

Ø Can be written in any way, like 4, 2.5, .876, 5., 1_123_456, 10E2, 45e.4, 0xbeef, 012.

Ø Integers and floating-point numbers are represented as we expected.

Ø Floating-point less than 1 can be written with a “.” at beginning.

Ø Commas not allowed, but underscores can be taken for expressing longer numbers.

Ø Exponents can be indicated with a upper/lower case “e” and a positive or negative number.

Ø Hexa/octa decimal numbers are represented by a leading 0x or a leading 0.

Ø Does not differentiate integer and floats, signed and unsigned, short and long numbers.

Ø It takes simply as scalar data and converts between number types.

Strings:

* Collection of characters.

* In other languages strings are stored in arrays.

* In perl strings are simply a another form of scalar data.

* May be represented in two ways ‘ or “ “.

* Can contain any kind of ASCII data including binary data.

* No size limits, limited only by the memory in the machine.

* Two differences between single and double quoted strings are,

o Double quoted string performs variable interpolation.

o Double quoted string can contain escape character.

Converting between Numbers and Strings:

· We don’t have to convert them.

· They are interchangeable.

· Depending upon context Perl automatically convert a string to a number or vice versa.

No comments:

Post a Comment