Chuck Zumbrun

Tales from Skunk Hill

Casting Perl to the Swine

This is why I hate Perl.

sub trim
{

return undef if not @_;
my @ret = map { $_ ||= ”; /^\s*(.*?)\s*$/s; $1 } @_;
return wantarray ? @ret : $ret[0];

}

Do you see the bug? Nor do I.

5 responses to “Casting Perl to the Swine”

  1. Paul Avatar
    Paul

    The answer is clearly

    sub trim
    {
    return undef if not @_;
    return map { my $str = $_; $str =~ s/^\s*(.*?)\s*$/$1/r; } @_;
    }

    1. chuck Avatar
      chuck

      Paul’s answer is right, of course. But I prefer:

      use String::Util;
      sub trim
      {

      return map {String::Util::trim( $_ ) } @_;

      }

      That’s why I’ll never be a Perl programmer.

      Coincidence that this is today’s xkcd comic? Sigil Cycle

  2. Missy Avatar
    Missy

    Are you guys allowed to talk like that on here?

    1. chuck Avatar
      chuck

      Missy, I participate in an ag discussion board where the use of grawlix is cause for banishment from the site. Here at zumbrun.net ‘free speech’ is our middle name.

  3. Dan Avatar
    Dan

    Knit one perl two

Leave a Reply

Your email address will not be published. Required fields are marked *