Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Confused about complex data structures.

by r.joseph (Hermit)
on Jan 18, 2001 at 05:17 UTC ( [id://52662]=note: print w/replies, xml ) Need Help??


in reply to Re: Confused about complex data structures.
in thread Confused about complex data structures.

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

Replies are listed 'Best First'.
Re: Re: Re: Confused about complex data structures.
by arturo (Vicar) on Jan 18, 2001 at 05:25 UTC

    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found