Always a better way

There’s always a better way in perl. Like methods to string unwanted whitespace from the beginning or end of strings.

Here are two examples ā€“ both using 2 lines of code. Which do you find more readable/maintainable?

$str =~ s/^\s+//;
$str =~ s/\s+$//;

or

use String::Util 'trim';

$str = trim($str);

Contributed by my good friend and colleague, gregor42.

This entry was posted in Development, Systems Analysis on by .

About phil

My name is Phil Lembo. In my day job Iā€™m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).