[EMAIL PROTECTED] wrote:
> 
> Hello Everyone,

Hello,

> I am a Perl newbie trying to learn as much Perl as I can.  I am trying to
> combine specific array elements into one single array element so that I can
> write
> to an Excel cell, where all the data will fit.
> 
> For instance I have,
> 
> array[0] = "F1: blue";
> array[1] = "F2: green";
> array[2] = "F3: red";
> array[3] = "F1: purple";
> array[4] = "F2: brown";
> array[4] = "F1: red";
> array[5] = "F2: pink";
> array[6] = "F3: blue";
> array[7] = "F4: white";
> 
> With the above information, I want to put all the F's in order before it
> starts over at 1 again.  For instance, I want to store array[0], array[1],
> and array[2] into a specific array element and then store array[3], array[4]
> into another specific array element, then I start over again with array[5].
> Each time I encounter an F1, I will store all the particular elements into
> one single array element.  Is this possible?

Is this what you want?

$ perl -le'
use Data::Dumper;
@array = ( "F1: blue",
           "F2: green",
           "F3: red",
           "F1: purple",
           "F2: brown",
           "F1: red",
           "F2: pink",
           "F3: blue",
           "F4: white" );

my ( $index, @new ) = -1;

push @{ $new[ /^F1:/ ? ++$index : $index ] }, $_ for @array;

print Dumper [EMAIL PROTECTED];
'
$VAR1 = [
          [
            'F1: blue',
            'F2: green',
            'F3: red'
          ],
          [
            'F1: purple',
            'F2: brown'
          ],
          [
            'F1: red',
            'F2: pink',
            'F3: blue',
            'F4: white'
          ]
        ];



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to