Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Re: Efficienty truncating a long string

by ysth (Canon)
on Dec 18, 2003 at 16:40 UTC ( #315563=note: print w/replies, xml ) Need Help??

in reply to Re: Efficienty truncating a long string
in thread Efficienty truncating a long string

Then you probably want to use 4-arg substr to truncate the buffer and save the fragment all at once:
$end = rindex($buffer, "\n"); if ($end < 0) { whoops, incomplete line } $fragment = substr($buffer, $end+1, length($buffer), '');
Note that length($buffer) is bigger than the actual length(buffer)-$end-1 you want, but specifying a length larger than is available is guaranteed to not cause problems; you'll just get what is there. If the buffer ends with "\n", you'll get an empty $fragment.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315563]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-09-28 19:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found