What Is Perl Array

What Is Perl Array

In Perl, array is a special type of variable. The array is used to store the list of values and each object of the list is termed as an element. Elements can either be a number, string, or any type of scalar data including another variable.

How do I create an array in Perl?

  1. # original string.
  2. $string = “Where-There-Is-A-Will-There-Is-A-Way”;
  3. # transforming strings into arrays.
  4. @string = split(‘-‘, $string);
  5. print “$string[4]\n”;

How do you access an array in Perl?

To get a single scalar out of an array, access it with the [] and a $ sigil. All arrays in Perl start at 0. Arrays can also be accessed from the end by using negative offsets from the end.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.