Perl Basic Datatypes

Share

This program uses variables of each of three basic types: scalar, array, and hash. Scalar variables can be numbers or strings, and the language will understand how to treat the data by the context of its use. An array is a linear collection of scalar data. A hash, or associative array, is a built-in data type that will associate a "key", with a piece of data.

The code presented here demonstrates how flexible these datatypes can be, such as having arrays that contain numbers as well as words, and the fact that array sizes can change dynamically. It also shows how the format of array output can be modified in a print statement using one of the special forms, "$,".

The output of the Perl script shown in purple has been interspersed between the Perl code in order to make it easier to follow what is happening in the program. The full program as well as the observed output are available as links at the bottom of the page.

About
Achchuthan Yogarajah

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

Google+ Badge

About Me

I’m an undergraduate for the B.Sc. Special in Computer Science at Department of Computer Science, University of Jaffna, Sri Lanka.

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

My main areas of interests are Programming, Web Development and Teaching.