Perl Data Types

« Previous Tutorial Next Tutorial »

There is no any need to specify a type for your data in a Perl program. There are following basic data types available in perl:

Scalars in Perl

Scalars in perl are simple variables, are preceded by a dollar ($) sign. A scalar in perl is either a number, a string, or a reference. Here are some examples of scalars in perl:

$first_name = "codes";
$last_name = "cracker";

Hashes in Perl

Hashes in perl are unordered sets of key/value pairs, you access using the keys are subscripts. Hashes in perl are preceded by a percent (%) sign. Here are some examples of hashes in perl:

%marks = ("first" => 100, "second" => 99, "third" => 98);
%roll = ("Devraj" => 15, "Vinay" => 46, "Ashwani" => 10);

Arrays in Perl

Arrays in perl are ordered list of scalars, you access with a numeric index, starts from 0. Arrays in perl are preceded by an at (@) sign. Here are some examples of arrays in perl:

@marks = (100, 99, 98);
@names = ("Devraj", "Vinary", "Ashwani");

« Previous Tutorial Next Tutorial »

Latest 5 Posts by CodesCracker


Quick Links
Signup - Login - Give Online Test