Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Splitting a long string

by dug (Chaplain)
on Aug 22, 2007 at 10:51 UTC ( [id://634303]=note: print w/replies, xml ) Need Help??


in reply to Splitting a long string

Another way to do this is to treat your data as an "in memory" file (see perldoc -f open). Setting the INPUT_RECORD_SEPARATOR variable to a reference to an integer will make the readline operator read that many bytes, or as many as it can until EOF. Putting that all together gives us:

#!/usr/bin/perl use warnings; use strict; my $string = "x" x 100_400; { open ( my $sth, "<", \$string ) or die $!; local $/ = \1_000; while ( my $chunk = <$sth> ) { print $chunk, "\n"; } }
-- Douglas Hunter

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found