Skip to content

Instantly share code, notes, and snippets.

@likhatskiy
Created February 2, 2010 07:23
Show Gist options
  • Save likhatskiy/292464 to your computer and use it in GitHub Desktop.
Save likhatskiy/292464 to your computer and use it in GitHub Desktop.
truncate string by length and word
print trunc("11111 222 4444", 9);
sub trunc {
s/\s+?\S+?$//, return $_ for my $str = substr shift, 0, (shift || 1) + 1;
}
sub trunc {#by http://what-me.livejournal.com/
$_[0] =~ /^.{0,$_[1]}(?!\S)/s ? $& : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment