Python/C++ vs. Perl/C++

Trim Whitespace

Here's a little exercise that should demonstrate that Python is a more natural scripting language option than Perl. This is but one of many possible examples.

The task: Trim leading and trailing whitespace from a string.

Comment on this topic

Perl
my $msg = "   spacey string  ";
$msg =~ s/^\s+//;
$msg =~ s/\s+$//;

Requires knowledge of regular expressions and then mental parsing of the regular expression to know what's going on. Or some comments.

Python
msg = "   spacey string  "
msg = msg.strip()

It's nice to be able to easily read code.