awohld has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Data::Dumper; # need to split up this array and send three values at a time to # sub "do_someting" my @array = qw( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ); while (@array) { my @array_segment; # if element isn't defined, don't get the NULL values push @array_segment, shift @array; push @array_segment, shift @array if defined $array[0]; push @array_segment, shift @array if defined $array[0]; do_something(@array_segment); } sub do_something { my @array = @_; print Dumper \@array; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Send Array to Subroutine, Three Elements at a Time
by GrandFather (Saint) on Oct 24, 2007 at 03:06 UTC | |
|
Re: Send Array to Subroutine, Three Elements at a Time
by dragonchild (Archbishop) on Oct 24, 2007 at 03:29 UTC | |
|
Re: Send Array to Subroutine, Three Elements at a Time
by BrowserUk (Patriarch) on Oct 24, 2007 at 03:22 UTC | |
|
Re: Send Array to Subroutine, Three Elements at a Time
by runrig (Abbot) on Oct 24, 2007 at 02:56 UTC | |
|
Re: Send Array to Subroutine, Three Elements at a Time
by petdance (Parson) on Oct 24, 2007 at 03:28 UTC | |
|
Re: Send Array to Subroutine, Three Elements at a Time
by aquarium (Curate) on Oct 24, 2007 at 03:01 UTC | |
by awohld (Hermit) on Oct 24, 2007 at 03:43 UTC |