Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: file tree to hash

by DrManhattan (Chaplain)
on Apr 06, 2003 at 02:40 UTC ( #248377=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-12-10 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?