in reply to need to put values (from unpack) into array-ref

Maybe this more succinctly captures the essence of what your code has to do?

#! perl -slw use strict; use Data::Dumper; my $b = "abefcdghijklmn"; my @a; @{ $a[ 0 ] } = ( 'start 0', unpack '(A1x)*', $b ); @{ $a[ 1 ] } = ( 'start 1', unpack '(xA1)*', $b ); print Dumper \@a; __END__ C:\test>539664 $VAR1 = [ [ 'start 0', 'a', 'e', 'c', 'g', 'i', 'k', 'm' ], [ 'start 1', 'b', 'f', 'd', 'h', 'j', 'l', 'n' ] ];

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: need to put values (from unpack) into array-ref
by BrowserUk (Patriarch) on Mar 28, 2006 at 11:03 UTC

    Better yet.

    #! perl -slw use strict; use Data::Dumper; my $b = "abefcdghijklmn"; my @a = ( [ 'start 0', unpack '(A1x)*', $b ], [ 'start 1', unpack '(xA1)*', $b ] ); print Dumper \@a; __END__ C:\test>539664 $VAR1 = [ [ 'start 0', 'a', 'e', 'c', 'g', 'i', 'k', 'm' ], [ 'start 1', 'b', 'f', 'd', 'h', 'j', 'l', 'n' ] ];

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Here's another way, although it uses an additional temporary variable...
      my $b = "abefcdghijklmn"; my @a = (['start 0'], ['start 1']); my $i = 0; push @{ $a[$i++ % 2] }, $_ for unpack('(A)*', $b);

      Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
      How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      THATS IT!!!!!

      Thanks a lot
      Luca
Re^2: need to put values (from unpack) into array-ref
by ikegami (Patriarch) on Mar 28, 2006 at 17:02 UTC
    The parent requires Perl 5.8. The following is more portable:
    my @a = ( [ 'start 0', $b =~ /(.)./g ], [ 'start 1', $b =~ /.(.)/g ], );