[ale] Perl Split Question

Keith R. Watson keith.watson at gtri.gatech.edu
Thu Jan 20 16:16:16 EST 2005


At 15:33 1/20/2005 -0500, you wrote:
>Is there a way to use split to split a string into segments of N
>characters.  I want to automatically wrap a long text string onto
>multiple lines.
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale

Assuming your not doing word wrapping in Perl


#!c:\perl\bin\perl.exe -w

use strict;

my $string ='1a2b3c4d5e6f7g8h9i';

my $string_length = length ($string);

my $segment_size = 3;

my $segment;

for (my $offset = 0; $offset <= $string_length; $offset += $segment_size) {

    $segment = substr ($string, $offset, $segment_size);

    print ($segment, "\n");
}


keith

-------------

Keith R. Watson                        GTRI/ISD
Systems Support Specialist III         Georgia Tech Research Institute
keith.watson at gtri.gatech.edu           Atlanta, GA  30332-0816
404-894-0836



More information about the Ale mailing list