[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Perl Split Question



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