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

Extract a wind reading

0 XP earned
Perl track: AdvancedMission: IntermediateRegular expressionsCapture groupsList context
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 / 6 challenges
LEARN THE CONCEPT

Understand it, then try it.

Perl regular expressions can capture a useful part of a larger string. The =~ operator applies a pattern, and parentheses capture the matching digits. In list context that capture can be assigned to a scalar variable. Here the pattern follows a literal field name, leaving the unit outside the captured number.

text_desk.pl
use strict;use warnings;my $reading = "wind=18km/h";my ($speed) = $reading =~ /wind=(\d+)/;print "$speed km/h\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.