HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PerlOperatorsStringsArrays (@)Hashes (%)Conditions (if)LoopsFunctions (sub)
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
📋 Array & Hash
Array (@)Hash (%)
🔁 Condition & Loop
🧩 Function (sub)
Perl›REFERENCE›Array & Hash
📋

Array & Hash

Arrays (@) and hashes (%).

CommandDescription
Array (@)Ordered values.
Hash (%)Key-value mapping.

Array (@)

Try it yourself →

Ordered values.

Syntax

my @a = (...); push @a, x;

Description

@ for arrays. $a[0] is the first element, push adds elements, scalar(@a) gives the element count, sort sorts them.

Example

my @a = (5, 10, 15);
push @a, 20;
print "$a[1]\n";
print scalar(@a), "\n";

Expected output

10
4

When to use?

Storing lists.

Hash (%)

Try it yourself →

Key-value mapping.

Syntax

my %h = (key => value);

Description

Hashes are defined with %. Values are accessed with $h{key} (using the $ sigil). keys returns the keys.

Example

my %person = (name => "Alex", age => 36);
print "$person{name}\n";

Expected output

Alex

When to use?

Structured data.

Common mistakes

  • ⚠️ Values are accessed with $h{key} (sigil $ not %).
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code