Color theme
0 day streak0 XPP1
PerlLearn mode
MISSION 1 OF 1

Resolve a media type

0 XP earned
Perl track: AdvancedMission: IntermediateHashesSigilsDynamic keys
Before you start this advanced track

Arrays, hashes, and regular expressions. Expect sigils, capture groups, and scalar/list context.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

A Perl hash stores values under named keys. The whole hash uses a percent sign, while one scalar value uses a dollar sign and braces around the key. An extension variable can supply that key dynamically. This keeps the same lookup expression useful for many different document extensions.

text_desk.pl
use strict;use warnings;my %types = (svg => "image/svg+xml", txt => "text/plain");my $extension = "svg";my $media_type = $types{$extension};print "$media_type\n";

Each mission is a complete Perl 5 script. Run one with perl. The scripts enable strict and warnings and use only built-in features; no modules, files, or external commands are needed.

Track the values line by line. Predict the result before running this example in your own editor.