20141010 always a better way - plembo/onemoretech GitHub Wiki

title: Always a better way link: https://onemoretech.wordpress.com/2014/10/10/always-a-better-way/ author: phil2nc description: post_id: 8619 created: 2014/10/10 10:06:52 created_gmt: 2014/10/10 14:06:52 comment_status: closed post_name: always-a-better-way status: publish post_type: post

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.

Copyright 2004-2019 Phil Lembo