develooper Front page | perl.beginners | Postings from October 2009

Re: split n characters into n chunks

Thread Previous | Thread Next
From:
John W. Krahn
Date:
October 25, 2009 10:42
Subject:
Re: split n characters into n chunks
Message ID:
4AE48DEA.9050207@shaw.ca
Michael Alipio wrote:
> Hi,

Hello,

> How do I split a word into n subsets?
> 
> my $word = "thequickbrown"
> 
> 
> If I want three subsets I should be able to create:
> 
> the
> heq
> equ
> ....
> upto
> ....
> own

$ perl -le'
my $word = "thequickbrown";
my $subsets = 3;
print for $word =~ /(?=(.{$subsets}))/g;
'
the
heq
equ
qui
uic
ick
ckb
kbr
bro
row
own



John
-- 
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About