http://www.perlmonks.org?node_id=229700


in reply to When does XML get to be too much?

With the XML schema you have right now, I hardly see the point of using XML in the first place. For such data a tab separated file format would do nicely. (You don't have to use XML, even if it's all the buzz right now.) Better than a tab separated file, use something like DBD::CSV, DB_File or the likes of it, i.e. a flat file that can be queried using SQL. That way you can migrate to a full fledged database should the need ever arise (this would imply that you just do a query, the data is permanently available in the database and doesn't have to be read each time the CGI script is executed).

From an XML design point of view, I'd prefer something like

<user ip="123.12.31.12" visits="3" time="1043370125"/>
since data should IMHO not go into the tag names, they're only there to structure the data, not to provide other info besides that.

Just my 2 cents, -gjb-

Replies are listed 'Best First'.
Re^2: (nrd) When does XML get to be too much?
by newrisedesigns (Curate) on Jan 24, 2003 at 21:22 UTC

    I know XML is a buzzword nowadays, and that's part of the reason I used it: practice. However, after I was done, I realized that it was probably a mistake.

    As for DBI... I don't know it. I read Dominus' article on using DBI, and I found it interesting, but I didn't grasp it right away. I will probably switch over to DBI and mySQL once I learn that.

    I was originally going to use a DB_File (Any_DBM, actually) database, but as far as I know, they don't allow for HoHs. If one does, I'd switch the program over. Any recommendations?

    John J Reiser
    newrisedesigns.com

      Wha wha what?!?!?! You haven't learned DBI yet? Unshift that item to the front of your queue and start reading! ;)

      Seriously, DBI and an RDBM can take a programmer to a new level of programming. I recommend any programmer out there who doesn't know how to program with a database learn how to do so very soon. The DBI part is not hard, but setting up and maintaining an RDBM can be. Luckily, there is the wonderful SQLite and the even more wonderful DBD::SQLite that allows you to use SQLite in Perl. One of the greatest benefits of using SQLite is that you get to use SQL, and if you use DBI with DBD::SQLite, then when the time comes to migrate to a "real" RDBM, all you should have to do is simply replace use DBD::SQLite with use DBD::mysql or use DBD::Pg.

      Do yourself a big favor and take some time out to learn these tools.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
      I was originally going to use a DB_File (Any_DBM, actually) database, but as far as I know, they don't allow for HoHs.

      Although, as gjb suggested, you can use MLDBM or you can use Data::Dumper or Storable to serialize your data structure by hand, the truth is that you don't even need an HoH in your case. You are storing the same data for each IP: visits and a timestamp. I would just store the two values in a single scalar delimited by a non-digit character of your choosing. (Consider using a comma, space, colon, semicolon, or pipe symbol as they are all commonly used for this kind of thing.) The right rule of thumb to follow in this case is "keep it simple."

      -sauoq
      "My two cents aren't worth a dime.";
      

      I've never used it myself, but you could have a go at MLDBM, it should do what you want.

      Hope this helps, -gjb-