in reply to substr question

$s = "I want to only show the first 100 characters or so of a string +that has more than 100, but I don't want to split it in the middle of + a word, so is there a way to do it instead of this:";; print $string =~ m[(^.{0,100})\s];; I want to only show the first 100 characters or so of a string that ha +s more than 100, but I don't print $s =~ m[(^.{0,$_})\s] for 20 .. 50;; I want to only show I want to only show I want to only show I want to only show the I want to only show the I want to only show the I want to only show the I want to only show the I want to only show the I want to only show the first I want to only show the first I want to only show the first I want to only show the first I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 I want to only show the first 100 characters I want to only show the first 100 characters I want to only show the first 100 characters I want to only show the first 100 characters or I want to only show the first 100 characters or I want to only show the first 100 characters or I want to only show the first 100 characters or so

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: substr question
by ikegami (Patriarch) on Jun 18, 2010 at 17:15 UTC

    That's the way I'd go too, but there's a little problem in your implementation:

    $ perl -le'print "abc def" =~ m[(^.{0,100})\s]' abc
    Fix:
    m[(^.{0,100})(?!\S)]
    m[(^.{0,100})(\s|$)]