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

Re: Splitting a long string

by holli (Abbot)
on Aug 22, 2007 at 11:38 UTC ( [id://634309]=note: print w/replies, xml ) Need Help??


in reply to Splitting a long string

There are basically two ways. One is destructive to the original string, the other is not but means more code:
my $long_string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; my $i = 0; my $readlength = 8; # non destructive while ( $i <= length($long_string) ) { my $part = substr( $long_string, $i, $readlength ); $i += $readlength; print "$part\n"; } # destructive while ( $long_string =~ s/^(.{1,$readlength})// ) { my $part = $1; print "$part\n"; }


holli, /regexed monk/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found