in reply to Confused about complex data structures.

Hm, what's in the files? How is the information structured NOW? Perhaps your data structure isn't the best one to use, but we won't know unless we know more about what kind of data the files are holding.

Or so I gather from reading your description!

You might want to check out RE: Data::Dumper (Adam: Sample Usage) for some info about how to store deeply nested data structures, or I like Storable and its freeze / thaw combination.

I hope this helps!

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
Re: Re: Confused about complex data structures.
by r.joseph (Hermit) on Jan 18, 2001 at 05:17 UTC
    Actually, the data is simply stored line by line. It is data for apartment bulidings (I am writing a property managment system), so a typical data file might look something like this:
    555 Robertson Blvd., Beverly Hills A nice fixer-uper 200 units 1500 sq. ft. $1500/wk. 01/01/2001 Bob Joe (310) 333-4444
    so, as you can see, I just want to grab all the data into an array somehow. I will know that, say, that array's index 3 is actually the size (1500 sq. ft.) of the unit or whatever, I just need the data.

    I hope that I am making more sense...as I said, I am pretty confused at this point - Thanks!

    R.Joseph

      Here's what I might do in this situation to avoid ever-deeper nested data: store each file as a scalar (works best if you know the data won't get *too* large). You could use a straight hash, where the keys are the filenames and the values are the contents of the files, stored as scalars. You could, when printing the data, get out the info you wanted. Here's some code:

      #!/usr/bin/perl -w # ... # I assume @files holds the list of filenames my %data; foreach (@files) { # this will allow us to store the whole file as a string! { local $/ = undef; # open FILE, $_ or die "Couldn't open $_: $!\n"; $data{$_} = <FILE>; close FILE; } } # to print : foreach (sort keys %data) { my ($city, $id) = split /_/, $_; print "City: $city, ID : $id\n"; print "====\n\n"; print $data{$_}, "=====\n"; }

      This way of representing might not be maximally efficient for searching, but if the data set's not *too* huge it won't be a worry. If your data set were to get *huge*, then look into an RDBMS; MySQL is available under the GPL =)

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor