in reply to Uninitialized Value Error When Interleaving

I don't know why you're getting the warning; I don't with this script:

#!/usr/bin/perl -w use strict; my @foo = ( 1 , 3 , 5 , 7 ); my @bar = ( 2 , 4 , 6 , 8 ); print STDOUT my @foobar = map { $_, shift @foo } @bar;
Unless, that is, you left the @baz line in. Note that you are destroying @foo in the process (by calling shift); if you do it more than once, you'll have an empty array the second time.

Replies are listed 'Best First'.
Re: Re: Uninitialized Value Error When Interleaving
by La12 (Sexton) on Jul 03, 2001 at 02:51 UTC
    what if you try this:
    #!/usr/bin/perl use warnings; use strict; my @foo = ( 1 , 3 , 5 , 7 ); my @bar = ( 2 , 4 , 6 , 8 ); print STDOUT my @foobar = map { $_, shift @foo } @bar;
      Um, that's exactly what I had (that is, "perl -w" is the same as "use warnings"). But as I and others have said, it's not usually a great idiom, as it's destructive to @foo. And you'll still have undefined values if @foo is shorter than @bar.