Monday, September 13, 2010

Datatypes in perl

Perl has 3 main datatypes - scalars, arrays and hashes which are prefixed with a symbol such as $ @ % when used as variables.

Scalars
So Perl is working, and you are working with Perl. Now for something more interesting than simple printing. Variables. Let's take simple scalar variables first. A scalar variable is a single value. Like $var=10 which sets the variables $var to the value of 10. Later, we'll look at lists like arrays and hashes, where @var refers to more than one value. For the moment, remember that Scalar is Singular.

Also note that these scalar value can be int , float strings what you have seen in some languages like c.
More of arrays and hashes see in other posts.

Loosely typed language
The idea of forcing a programmer to declare what sort of variable is being created is called typing. As Perl doesn't by default enforce any rules on typing, it is said to be a loosely typed language, as opposed to something like C++ which is strongly typed. One must keep in mind that perl was designed for shorter and fast things...rather than v.big projects.

No comments:

Post a Comment