Re: [MacPerl-AnyPerl] question about "my" declarations

[email protected] (Bart Lateur) Fri, 28 Sep 2001 17:15:58 +0200
Newsgroups perl.macperl.anyperl
Organization MediaMind
Message-ID <[email protected]>
On Thu, 27 Sep 2001 09:30:19 -0700 (PDT), Tejasvini Prasad wrote:

>I am trying to read data from a series of files as
>references into an array. Every element of my array is
>a reference to another array containing the values in
>one of the files.

OK, I hope I understand you correctly... will this do?

	my $argv = '';
	my(@contents, $current);
	while(<ARGV>) {
	     if($ARGV ne $argv) {
	          push @contents, $current = [];
	          $argv = $ARGV;
	     }
	     push @$current, $_;
	}

If you  accept a hash of files instead of an array, things can get a lot
easier, as Perl's built-in magic can take care of a lot of the nitty
gritty:

#! perl -w
	@ARGV = glob('test.*');
	my %contents;
	while(<ARGV>) {
	     push @{$contents{$ARGV}}, $_;
	}

-- 
	Bart.