Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Splitting a long string

by dug (Chaplain)
on Aug 22, 2007 at 10:51 UTC ( #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? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-03-28 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (66 votes). Check out past polls.

    Notices?