Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: substr question

by BrowserUk (Pope)
on Jun 18, 2010 at 17:08 UTC ( #845414=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re^2: substr question
by ikegami (Pope) 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|$)]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://845414]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-06-19 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (115 votes). Check out past polls.

    Notices?