Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | 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;
		
		
comments powered by Disqus