Extracting real data from an exported file in PHP or Perl
Archive - Originally posted on "The Horse's Mouth" - 2009-07-25 07:22:13 - Graham Ellis"Just give me the data". Where there's a requirement to take data from another program into a Perl or PHP script, it's often easier simply to take the data in a format that it's offered / exported from that other program and use code in Perl or PHP to make appropriate use of that data. The alternative of getting the data supplier to do all sorts of manipulation is, frankly, more trouble than it's worth.
Lisa has passed me a data flow - a dump of all the Melksham retail businesses - from the map she's been working on and is being shown at the West Wilts Show today. It's good, it contains what I need, but it's formatted with the map in mind rather than with the data meaning ("how it should look" rather than "what it means"). Now I could ask for it in XML ;-) ... of I could use Perl or PHP and their powerful text handlers. I have chose to do the latter.
Here is the main "what's this line" decision code - in PHP:
if (ereg("^ ",$record)) { # MAIN HEADER
elseif (count($els) == 1) { # SUB HEAD
elseif (count($els) == 2 and ereg("^[1-9]",$els[1])) { # OUT OF TOWN on map
elseif (count($els) == 2) { # OUT OF TOWN LOCATION not on map
elseif (count($els) == 3) { # IN TOWN LOCATION
else { # ERROR
and here is the formatted list of Melksham retailers I have produced from it. The source code is here. The next stage is going to be to produce listings by area ... as I have the data in my PHP code now, that will be easy. And I know that I need to put a good look and feel onto it!
You can download the map from here.