Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Efficienty truncating a long string

by ysth (Canon)
on Dec 18, 2003 at 16:40 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found