in reply to Unique Variable names...
Yeah, no kidding that's not going to work. You create %hash every iteration through @filename. Try something like:%hash={"$file"=>@final_data}; #this hash assignment +doesn't wor +k close (FILE); } @values=values(%hash);
$hash{$file} = \@final_data; close (FILE); } @values=values(%hash);
I'm not sure what you're doing with get_targets(), so I'll ignore it for now.
I would implement the subset of your script that doesn't deal with get_targets() as such:
#!/usr/local/bin/perl #Why do you need this?!? #use Cwd qw(cdir); use IO::Dir; use IO::File; print "Please enter the name and location of the directory to parse:\n +"; chomp(my $directory = <STDIN>); my $dh = IO::Dir->new($directory) || die "Cannot open directory '$directory': $!\n"; my @filenames; push @filenames, $_ for map { "$directory/$_" } grep !/^\.\.?/, $dh->r +ead; $dh->close; my %file_data; foreach my $filename (@filenames) { my @final_data; # Why do you need to do this?!? #chdir "./data"; my $fh = IO::File->new($file) || die "Cannot open file '$file': $!\n"; my $i = 0; while (<$fh>) { next while $i++ <= 14; push @{$file_data{$file}}, (split /\t/)[3]; } $fh->close; } # Now, at this point, you have a hash called %file_data # which is keyed by filename. Each filename points to an # array reference contained the values in the 4th column, # starting at the 15th line. What do you want to do with it?
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Unique Variable names...
by BUU (Prior) on Jul 30, 2003 at 00:51 UTC | |
by dragonchild (Archbishop) on Jul 30, 2003 at 13:41 UTC | |
|
Re: Re: Unique Variable names...
by bioinformatics (Friar) on Jul 30, 2003 at 15:49 UTC | |
by Limbic~Region (Chancellor) on Jul 30, 2003 at 15:59 UTC | |
|
Re: Re: Unique Variable names...
by bioinformatics (Friar) on Jul 30, 2003 at 19:50 UTC |