[Za-pm] flat file test script

Mark Hewitt mh2 at isis.co.za
Tue Aug 12 16:17:12 CDT 2003


Hi,

Its pretty late (after 23:00!!) and I still have alot of work to complete before tomorrow, so I'll just make breif comments, I'll try respond in more detail tomorrow if I get a free moment. Pls find my comments in the original text...

  >>----- Original Message ----- 
  >>From: Walter Kruse 
  >>To: za-pm at mail.pm.org 
  >>Sent: Tuesday, August 12, 2003 1:58 PM
  >>Subject: [Za-pm] flat file test script

   >>Hi everyone - hope someone will help a newbie
  >>I need to simulate the importing of a flat file into two tables in a db for test purposes. The file has very long records, which aren't separated into fields >>by any character. Rather, the program under test counts characters. So chars 1-8 go in table 1, chars 9-12 to table 2, chars 13-40 to table 1 again and so 
  >>on. I want to use a perl script as the records are very long (+/- 88 fields) to create two new text files and sort the records between the two files as I 

  Okay, a couple of points:
  1. The example above puzzles me, as I would have expected the umbers of chars goin into each table to be the same each time? Or do you have 88 fields be "record", where the 88 get split between the 2 dbs, after reading all 88, the script can now process "record 2" in flat file?
  2. What do you mean by "db"? Another flat file, or a real SQL database?

  >>specify. The problem, I am faced with, however, is the counting and sorting of the chars. I don't have a clue. This is as far as I got:

  Try substr or unpack.
  From your desription, many fields of specified length this sounds like a job for unpack.
  The Perl CookBook has a very useful function called cut2fmt() or something, it takes "cut-off" values as parameters, and returns the unpack format string required to unpack in that format. In your case, the unpack would begin like:

  @a = unpack( "A8 A4 A27");

  You may want to generate this string programatically is you have 88 fields to go in the unpack!

  >>.#!/usr/bin/perl
  >>open (FILE, "testfile") || die "Can't open file !\n";
  >>@file = <FILE>;

  >>my($record) = split(/\n/, @file);

  This is not needed, you destroy the content on $record in the next statement, and the entire file content is already broken into lines by the @file = <file> statement.
  >>foreach $record (@file)
  >>{

  >>  my($char) = split(//, $record);

  # You'll want to use substr/unpack here, followed by the write to the database

  @a = unpack( "A8 A4 A27");


  # this loop iterates over all parameters in the last extraction and writes them alternatly (as you showed in ur example) to the databases
  # its scalable like this and will handle any  number of fields in the unpack token
  $i = 0;
  foreach $a (@a)
  {
      if ( $i++ & 1 )
      {
          # add $a to database 1
      }
      else
      {
          # add $a to database 2
      }
  } 
    
  >>}
  >>close FILE;


  Does this help you at all?

  Thanks,
  Mark
  ----------------------------------------------------------------------------
  Windows, Linux and Internet Development Consultant
  Email: corporate at scriptsmiths.com
  Web: http://www.scriptsmiths.com
  Cell: +27 82 9655295
  ---------------------------------------------------------------------------


  >>Kind Regards
  >>Walter Kruse 
  >>MultiChoice Information Technology 
  >>Software test analyst - Application Delivery and Support Team 
  >>Tel:    +27 (0) 11 289-4552 
  >>Cell:   +27 (0) 82 660 7288 
  >>Email:  walterk at multichoice.co.za 
  >>Personal web page: http://www.ou-ryperd.net 

  >>*********************************************************************************************************************
  >>Everything in this e-mail and attachments relating to the official business of MultiChoice Africa is proprietary to the company. Any >>view or opinion expressed in this message may be the view of the individual and should not automatically be ascribed to the >>company.  If you are not the intended recipient, you may not peruse, use, disseminate, distribute or copy this message. If you have >>received this message in error, please notify the sender immediately by email, facsimile or telephone and destroy the original >>message.
  >>*********************************************************************************************************************


------------------------------------------------------------------------------


  _______________________________________________


  Za-pm mailing list
  Za-pm at mail.pm.org
  http://mail.pm.org/mailman/listinfo/za-pm

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/za-pm/attachments/20030812/d4472b27/attachment.htm


More information about the Za-pm mailing list