in reply to truncating a line

I haven't seen anyone answer with this one yet, so I thought I'd throw it out there. Sorry if it's a repeat. I'm not as proficient with all the regex tricks as I'd like to be.
$line =~ /^(.{0,17})/; print "$1\n";

If that's a rehash, then please let me know. I think it's close to BrowserUK's answer, but they have an if that mine doesn't. Thanks.

Replies are listed 'Best First'.
Re: Re: truncating a line
by tilly (Archbishop) on Jul 01, 2003 at 16:18 UTC
    Removing an if is only worthwhile if you still have a correct solution.

    Yours does not add the requested "..." when it is needed. (And like the other RE solution will also mess up if there is a newline in there.)

      Argh. Thanks tilly. I was so jazzed that I knew how to approach the first half, I overlooked the second. Read the spec, read the spec, read the spec.