data types in perl

www.igif‮c.aedit‬om

Perl has several built-in data types, including:

  1. Scalars: Scalars are single values, such as numbers or strings. In Perl, scalars are represented using the $ sigil. For example:
my $x = 42; # a numeric scalar
my $y = "Hello, World!"; # a string scalar
  1. Arrays: Arrays are ordered lists of scalars. In Perl, arrays are represented using the @ sigil. For example:
my @array = (1, 2, 3, 4, 5); # an array of numeric scalars
  1. Hashes: Hashes are unordered collections of key-value pairs. In Perl, hashes are represented using the % sigil. For example:
my %hash = (
  "name" => "Alice",
  "age" => 30,
  "occupation" => "programmer"
); # a hash of string scalars
  1. References: References are a way of referring to another variable or data structure. In Perl, references are represented using the \ operator. For example:
my $array_ref = [1, 2, 3, 4, 5]; # a reference to an array
my $hash_ref = { "name" => "Bob", "age" => 40 }; # a reference to a hash
  1. Glob: Glob is a data type that allows you to manipulate files and directories. In Perl, globs are represented using the * sigil. For example:
my $handle = *STDOUT; # a reference to standard output
print $handle "Hello, World!\n"; # writes to standard output

These are just a few examples of the data types available in Perl. Perl also has support for regular expressions, objects, and more advanced data structures like multidimensional arrays and complex hashes.