#!/usr/bin/perl use strict; use warnings; use bug::myitem; sub generate { my $list = shift; my @data; my $i=0; foreach my $f (@$list) { my $item = bug::myitem->new($i++, $f); push(@data, [$item, $i]); } return \@data; } my $data; if (scalar(@ARGV)>0) { $data = generate(\@ARGV); } else { die "syntax: ..." } print "Before:\n"; foreach my $item (@$data) { print "item->[0]=".$item->[0]." ; item->[1]=".$item->[1]."\n"; } my $dataStuff = map { $_->[0]->getContent() } @$data; print "After:\n"; foreach my $item (@$data) { print "item->[0]=".$item->[0]." ; item->[1]=".$item->[1]."\n"; } #### package bug::myitem; use strict; use warnings; sub new { my ($class, $id, $file) = @_; my $self; $self->{id} = $id; $self->{file} = $file; bless($self, $class); return $self; } sub getContent() { my $self = shift; my $fh; my $res; open($fh, "<",$self->{file}) or die "cannot open '".$self->{file}."'"; while (<$fh>) { chomp; $res .= $_."***"; } return $res; } 1;