in reply to file tree to hash

Here's another eval() solution.

#!/usr/bin/perl use strict; use Data::Dumper; my %hash; my $value = "determined at run time"; while (<DATA>) { chomp; eval '$hash{' . join( "}{", split(/\//) ) . "} = '$value'"; } print Dumper(\%hash); __DATA__ root/dir1/file1 root/dir1/file2 root/dir1/file3 root/dir2/file1
Edit: merlyn is correct. Don't ever use this. A file named "root/dir1/file1}=1;`someprogram`;$hash{foo" could be used to execute an external program.

-Matt

Replies are listed 'Best First'.
•Re: Re: file tree to hash
by merlyn (Sage) on Apr 08, 2003 at 04:44 UTC