Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: file tree to hash

by DrManhattan (Chaplain)
on Apr 06, 2003 at 02:40 UTC ( [id://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 drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-19 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found