Majian wrote: > 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
use strict; use warnings; > > my $string = "1234567890abcdefghijABCDEFGHIJK"; > my $n = 2; # $n is group size. > my @groups = unpack "a$n" x (length( $string ) /$n ), $string; > > print @groups; print "@groups\n"; # or use Data::Dumper; print Dumper \...@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 !! > -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/