Hash question

B

Bryan

I have the following hash:
$VAR1 = {
'directory' => {
'name' => 'GLMSR',
'directory' => {
'A17' => {
'file' => {
'name' => 'A17.xml'
}
},
'F19' => {
'file' => {
'name' => 'F19.xml'
}
},
'B01' => {
'file' => {
'name' => 'B01.xml'
}
}
}
}
};


I need to iterate over this structure, and for each directory, check if
it exists in a new location- if it doesnt, create the directory on disk.
If the hash element is a file, then I need to do something specific
with the file, and then write out a new file to the corresponding directory.

So at the end, I would have a duplicate directory structure on disk,
which contains the processed files instead of the originals.

What is the appropriate way to do this?

Thanks,
B
 
X

xhoster

Bryan said:
I have the following hash:
$VAR1 = {
'directory' => {
'name' => 'GLMSR',
'directory' => {
'A17' => {
'file' => {
'name' => 'A17.xml'
}
},
'F19' => {
'file' => {
'name' => 'F19.xml'
}
},
'B01' => {
'file' => {
'name' => 'B01.xml'
}
}
}
}
};

That is a pretty gnarly hash. It looks like you took Evotec's crappy XML
and just converted it to a hash.

Can the top level hash have more than one key-value pair? If so, what
format would other ones have? If not, then what is the point of it
existing? Can directories keep nesting beyond what you show, and if so how
would that look? If the Well hash can only have one key, whose value is
hash that can only have one key, what is the point of having all the
hashes?
I need to iterate over this structure, and for each directory, check if
it exists

perldoc -f -X, look for "-d"
in a new location-

That suggests it already exists in an old location. Why not just walk
through the filesystem structure of the old location, rather than walking
through a poorly designed hash based on the filesystem structure?
if it doesnt, create the directory on disk.

perldoc -f mkdir
If the hash element is a file, then I need to do something specific
with the file, and then write out a new file to the corresponding
directory.

How you do something depends on what that something is.
So at the end, I would have a duplicate directory structure on disk,
which contains the processed files instead of the originals.

What is the appropriate way to do this?

Learn Perl, or hire someone who already knows.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top