in reply to how to splice an array?

You're starting with a string, so why put it in a one-element array?

Anyway, here's a simple solution with regexps. It allows a trailing element that's too short. (If you don't want that, drop the "1," from the quantification.)

my $str = "PERLPERLPEBLPEBLPERL"; my @parts = $str =~ /.{1,4}/g;

Replies are listed 'Best First'.
Re^2: how to splice an array?
by heidi (Sexton) on Oct 11, 2006 at 16:31 UTC
    Re Re: how to splice an array?sorry for this correction, but my out put from the previous step of the program gives me the @array containing those elements as a single character.can i operate on an array rather than starting with a string.

      Here is one way to do it with splice and join:

      use strict; use warnings; my $string = "PERLPERLPEBLPEBLPERL"; my @array = split( '', $string ); while( scalar @array ) { my $extracted = join( '', splice( @array, 0, 4 ) ); print "[$extracted]\n"; }