Dear list:
 I have a  question  on learning Perl . Please give me a help .

 The problem is :

How can I split a string into chunks of size n bytes?Like this :
#!/usr/bin/perl

my $string = "1234567890abcdefghijABCDEFGHIJK";
my $n = 2;    # $n is group size.
my @groups = unpack "a$n" x (length( $string ) /$n ), $string;

print @groups;


when I run it, the screen displays the $string value, like
"1234567890abcdefghijABCDEFGHIJK"

but I want the groups and the group size is 2 .

Is it wrong that this phrase (length($string)/$n ?


Thanks in advance !!

Reply via email to