Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

第 3 章 Array, Hash

		
my @source = qw( title text1 text2 text3 text4 title text1 text2 text3 );

my $i = 0;
my @records = ();
foreach my $sour (@source)
{
    if ($sour eq 'title')
    {
        $records[$i] = { title => $sour };
        $i++;
    }
    else
    {
        push @{ $records[$i - 1]->{value} }, $sour;
    }
}

use Data::Dumper;
print Dumper \@records;