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;