in reply to variation on splitting a string into elements of an array
in thread splitting a sequence using unpack

A slightly longer but easily configurable code
use strict ; use warnings ; ##updated according to suggestions my $string="atccatccctttaat" ; my $left_out=2 ; my $template = "x$left_out" ; $template .= "a3" x ((length($string)-$left_out)/3) ; my @array=unpack($template, $string) ; local $"="\n" ; print "@array" ;
$left_out will contain the number of characters you want to skip from the starting.

Manav

Replies are listed 'Best First'.
Re^2: variation on splitting a string into elements of an array
by fizbin (Chaplain) on Mar 02, 2005 at 17:07 UTC
    Why these two lines:
    my $template = "a" x $left_out ; shift @array while($left_out--);
    When you could easily use this one line instead: (and earlier responses had used the "x" template character, and you'd clearly read those earlier responses)
    my $template = "x$left_out" ;
    This also has the advantage that you don't trash $left_out, in case you need it later. Of course, if you're using a perl 5.8 or higher, I'd really recommend my solution instead.
    -- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
      You are right on about the use of 'x'. btw, I didnt read the earlier comments as they were not there when I answered.

      Manav