Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scaler to array

Status
Not open for further replies.

jamsman

Technical User
Jul 22, 2005
38
DE
i have a string that contains the following:

{
'Attachment03' => {
'Filesize' => '3321',
'Filename' => 'res.xml',
'Description' => 'Miricals can come true'
},
'Attachment01' => {
'Filesize' => '3321',
'Filename' => 'res.xml',
'Description' => 'Does it work'
},
'Attachment02' => {
'Filesize' => '3321',
'Filename' => 'res.xml',
'Description' => 'Miricals can come true'
}
}


now the number of 'Attachments' can be any number i need to get this information in to some kind of array that also contains the other informtion in a field


any ideas
 
how would you want to store, all the values you have now, in your new "array"??

Why would you want an array?? when you have everything in a hash of hashes, which is more editable and a lot faster...


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Are you sure it's a string? It looks like a data structure. If it really is a string (from a config file?) then you could autovivify it as a data structure like this
Code:
my $data;
eval "\$data = $string";
die $@ if $@; # syntax error in string

# now use your data like this
foreach my $att ( sort keys %$data ) {
  # att is Attachment01, Attachment02, Attachment03 in turn
  print "Filesize is $data->{$att}{Filesize}\n";
  print "Filename is $data->{$att}{Filename}\n";
  print "Description is $data->{$att}{Description}\n";
}

Is this what you are after?

f

"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top