Perl best practices (was: question ... Split operator in Perl)
Ben Scott
dragonhawk at gmail.com
Thu Sep 13 08:48:26 EDT 2007
On 9/13/07, John Abreau <jabr at blu.org> wrote:
>> s/^[\x20\t]*//; # trim leading space
>> s/[\x20\t]*$//; # trim trailing space
>
> Any particular reason to use [\x20\t] instead of \s ?
\s would also eat newlines and similar. At a minimum, it would have
to explicitly print with "\n" and use the -n switch instead of the -p
switch. Which would be fine. But if the file contains non-native
line endings, it can result in those getting mangled, or so I've
found. I've got a lot of such files hanging around on my system.
Just eating space and tab worked better for me.
OTOH, \s should eat other kinds of in-line whitespace that might be
encountered, including anything Unicode dishes up. So that might be
better for some situations.
YMMV. Or, since this is Perl we're talking about: TIMTOWTDI. ;-)
-- Ben
More information about the gnhlug-discuss
mailing list