--- "D. Bolliger" <[EMAIL PROTECTED]> wrote:
> Hello Klute
>
> (please don't top post to keep the conversation
> readable)
>
> The following script extracts the information out
of
> your sample data.
> There are no checks if the data format is
"correct"
> (nesting order, additional
> text).
>
> It does not result in an array of hashes, but in a
> single hash.
> Modify it if needed :-)
>
> Dani
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> my %data;
>
> # holds the current first and second level
> #
> my ($parent_group, $aff_group);
>
> while (<DATA>) {
>
> # a loop block, so we can use next
> {
> # skip blank lines
> /^\s*$/
> and next;
>
> # record current first level
> /^A.*?: (.*)/ and $parent_group=$1
> and next;
>
> # record current second level
> /^\s+->.*?: (.*)/ and $aff_group=$1
> and next;
>
> # fill %data, with completed three levels
> /-->.*?: (\d+).*?: (\w+)/
> and
> $data{$parent_group}{$aff_group}{$1}=$2;
> }
>
> }
>
> print Data::Dumper::Dumper \%data;
>
>
> __DATA__
> Affiliate Parent Group: Google
> -> Affiliate Group: Google Advertiser
> --> Affiliate (Aff Id: 1, Aff Name: Frank)
> --> Affiliate (Aff Id: 2, Aff Name: Mary)
>
> -> Affiliate Group: Google Publisher
> --> Affiliate (Aff Id: 3, Aff Name: Lori)
> --> Affiliate (Aff Id: 4, Aff Name: Mike)
>
>
> Affiliate Parent Group: Yahoo
> -> Affiliate Group: Yahoo Advertiser
> --> Affiliate (Aff Id: 5, Aff Name: Marlene)
> --> Affiliate (Aff Id: 6, Aff Name: Larry)
> -> Affiliate Group: Yahoo Publisher
> --> Affiliate (Aff Id: 7, Aff Name: Alex)
> --> Affiliate (Aff Id: 8, Aff Name: Glenn)
>
Thanks guys for your replies. It works! So what data
structure am I dealing with here?
$data{$parent_group}{$aff_group}{$1}=$2;
Best,
James