Lesson 34 of 55
8 mins readPython Anonymous Arrays ([]) & Anonymous Hashes ({})
In Plain English
Anonymous arrays `[1, 2, 3]` and anonymous hashes `{ key => "val" }` construct data structures directly as references without requiring an intermediate named variable.
Deep Dive: How It Works
Square Brackets ([]): Creates an anonymous array reference.
Curly Braces ({}): Creates an anonymous hash reference in expression context.
Memory Management: Perl automatically garbage-collects references when reference count drops to 0.
Core Rules to Remember

[ ... ] for Array Ref: Instantly builds an unblessed array reference.

{ ... } for Hash Ref: Instantly builds an unblessed hash reference.
Live Interactive Example
Hit Run Code to see it liveAnonymous References in Practice
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: [] created an anonymous array reference and {} created an anonymous hash reference.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Create In-Line Hash Ref
Create an anonymous hash reference `my $config = { env => "production", debug => 0 };`
Print `"Environment: $config->{env}\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.