Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: greater efficiency required (ls, glob, or readdir?)

by jperlq (Acolyte)
on Aug 27, 2008 at 20:09 UTC ( [id://707290]=note: print w/replies, xml ) Need Help??


in reply to Re: greater efficiency required (ls, glob, or readdir?)
in thread greater efficiency required (ls, glob, or readdir?)

Thanks, I got your version to work with very few changes.
my $dir = '/path/to/data/directory'; my %hash; opendir my $DH, $dir or die "cannot open '$dir' $!"; while (my $file = readdir $DH ) { next if $file =~ /~$/; next if -d $file; open my $FH, "<", "$dir/$file" or die "Cannot open '$dir/$file +' $!"; while ( my $line = <$FH> ) { next if /^#/ || !length($line); my ($key, @values ) = split(/\t/, $line); $hash{ $file }{ $key } = \@values; } }
It even seems to work quite a bit faster than the ls/cat combo.

Replies are listed 'Best First'.
Re^3: greater efficiency required (ls, glob, or readdir?)
by jwkrahn (Abbot) on Aug 27, 2008 at 21:03 UTC

    You need to change: next if -d $file; to next if -d "$dir/$file";

    You need to change: next if /^#/ || !length($line); to next if $line =~ /^#/ || !length($line);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://707290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (None)
    As of 2024-04-25 03:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found