in reply to Re^4: how to shorten given string?
in thread how to shorten given string?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: how to shorten given string?
by bart (Canon) on Oct 14, 2004 at 03:12 UTC |