in reply to Re: How do I extract data?
in thread How do I extract data?
Now you have an array of CalendarEntry objects in @entries. You can convert that into a hash, with key = entry name and value = array(ref) of dates, like so: my %entries = map { $_->{'name'} => $_->{'dates'} } @entries; Then you can look things up as before: @some_dates = @{ $entries{'Calendar_2_test'} };{ package CalendarEntry; sub new { my $pkg = shift; bless { dates => [], name => shift, }, $pkg } sub add_date { my $self = shift; push @{ $self->{'dates'} }, @_; } } # end CalendarEntry. my @entries; # array of CalendarEntry objects. my $entry; while (<>) { chomp; if ( /calendar: (.*)/ ) { defined $entry and push @entries, $entry; $entry = new CalendarEntry $1; } else { $entry->add_date( $_ ); } } defined $entry and push @entries, $entry;
jdporter
...porque es dificil estar guapo y blanco.
|
|---|