I'll accept that reasoning. :)
Here's a version of your 'add elipses' regexp that shifts the code evaluation to the left side of the s/// operator by using (?{...}). Not as clear as your solution, but another way to do it. I'm always looking for entertaining ways to use (?{...}). ...your approach is more appropriate for actual use though. Keep mine in the cage.
$string =~ s/^(.{1,20})(?{(length($_)>pos)?'...':''}).*$/$1$^R/;
Just for fun... ;)
Dave
In reply to Re^5: how to shorten given string?
by davido
in thread how to shorten given string?
by mellin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |