in reply to greater efficiency required (ls, glob, or readdir?)
For efficiency you want something like this:
my $dir = '/Path/to/a/data/directory'; opendir my $DH, $dir or die "Cannot open '$dir' $!"; my %hash; while ( my $file = readdir $DH ) { next if $file =~ /~$/; open my $FH, '<', "$dir/$file" or die "Cannot open '$dir/$file' $! +"; while ( my $line = <$FH> ) { next if /^#/ || !/\S/; my ( $key, @values ) = split /\t/; $hash{ $file }{ $key } = \@values; } }
Update: I realised that the while loop is incorrect, it should be:
while ( my $line = <$FH> ) { next if $line =~ /^#/ || $line !~ /\S/; my ( $key, @values ) = split /\t/, $line; $hash{ $file }{ $key } = \@values; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: greater efficiency required (ls, glob, or readdir?)
by linuxer (Curate) on Aug 27, 2008 at 19:09 UTC | |
|
Re^2: greater efficiency required (ls, glob, or readdir?)
by jperlq (Acolyte) on Aug 27, 2008 at 20:09 UTC | |
by jwkrahn (Abbot) on Aug 27, 2008 at 21:03 UTC |