in reply to break up text string into 70 character long tokens

@tokens = /(.{0,70})/g; ?? e.g.
pointo1d@unforgiven:~/workspace/SVC-Class-Utils$ perl -MData::Dumper - +e '@t = "abcdefghijk" =~ /(.{0,2})/g;print Dumper \@t' $VAR1 = [ 'ab', 'cd', 'ef', 'gh', 'ij', 'k', '' ]; pointo1d@unforgiven:~/workspace/SVC-Class-Utils$

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: break up text string into 70 character long tokens
by AnomalousMonk (Archbishop) on Jan 08, 2009 at 03:38 UTC
    Using the regex  /.{1,$n}/g gets rid of that pesky empty string at the end of the list and also allows variable width.
    >perl -wMstrict -MData::Dumper -le "my $width = shift; my @t = 'abcdefghijklmno' =~ /.{1,$width}/g; print Dumper \@t; " 4 $VAR1 = [ 'abcd', 'efgh', 'ijkl', 'mno' ]; >perl -wMstrict -MData::Dumper -le "my $width = shift; my @t = 'abcdefghijklmno' =~ /.{1,$width}/g; print Dumper \@t; " 3 $VAR1 = [ 'abc', 'def', 'ghi', 'jkl', 'mno' ]; >perl -wMstrict -MData::Dumper -le "my $width = shift; my @t = 'abcdefghijklmno' =~ /.{1,$width}/g; print Dumper \@t; " 2 $VAR1 = [ 'ab', 'cd', 'ef', 'gh', 'ij', 'kl', 'mn', 'o' ];