* "Smith, Derek" <[EMAIL PROTECTED]> [2006-08-17T10:52:16] > What module would be ideal for getting a recursive listing into an array > or hash?
Your code, below, makes it look like you really mean "for getting a recursive directory listing." > I was looking at IO::All???? Is that a question? Do multiple question marks convert into a period or something? Here's a crappy little directory lister I wrote once: http://rjbs.manxome.org/hacks/perl/tree You could pretty easily turn that into a hash-builder. Instead of passing in an indent level, just pass in the directory name. Instead of printing, return a hashref. So, for this: a/ a/b.txt a/c.txt a/d/ a/d/e.txt You could end up with: { a => [ b.txt c.txt { d => [ e.txt ] } ] } I've attached an example. -- rjbs
#!/usr/bin/perl use strict; use warnings; sub recursedir { my $dir = shift; my $hashref = shift || {}; die "error: $dir is not a directory\n" unless -d $dir; my @contents; my ($dname) = $dir =~ /([^\/]+)$/; foreach my $d (glob("$dir/*")) { my ($fname) = $d =~ /([^\/]+)$/; if (-d $d and not -l $d) { push @contents, recursedir("$d"); } else { push @contents, $fname; } } return { $dname => [EMAIL PROTECTED] }; } use Data::Dumper; print Dumper( recursedir($ARGV[0] || '.') );
signature.asc
Description: Digital signature