in reply to Splitting a long string

For a modest size string like that:

for my $temp ($str =~ /.{1,1000}/g) { # do stuff with $temp }

is probably sufficiently fast.

Update: s/1000/1,1000/ per almut's catch.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Splitting a long string
by almut (Canon) on Aug 22, 2007 at 09:59 UTC

    Minor nitpick: to get the last block of 400 chars as well, that regex should be /.{1,1000}/g, i.e. min 1, max 1000.

Re^2: Splitting a long string
by uvnew (Acolyte) on Aug 22, 2007 at 11:15 UTC
    Yep, that's perfect. Thank you all!