in reply to Amusing note on my own stupidity (longish)

For scalars, you can use the readonly function from Scalar::Util

Update: There's even a String::Util module that provides a trim function.

  • Comment on Re: Amusing note on my own stupidity (longish)

Replies are listed 'Best First'.
Re^2: Amusing note on my own stupidity (longish)
by almut (Canon) on Jan 12, 2010 at 17:48 UTC

    There's even Scalar::Readonly that allows you to modify readonly variables :)

    #!/usr/bin/perl use Scalar::Readonly 'readonly_off'; sub trim { for (@_) { readonly_off($_); s/^\s+//; s/\s+$//; } } for (' foo ', ' bar ') { trim($_); print ">>$_<<\n"; } __END__ >>foo<< >>bar<<