<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>Hi 
Mark</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>sorry, I did not 
make myself very clear. I don't know if everyone that posts get a message saying 
the moderator has to approve the post (apparently I am not a member), hence the 
post was received so late.</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>&nbsp;I am 
simulating the import of the file into Oracle, in order to compare my 2 new 
files with what the tables in Oracle are populated with. This is to see that the 
program (under test) that splits the file and populates the tables, did its work 
correctly. Little complicated. Anyhoo, I now have a working hack that is good 
enough for me to use. Here it is:</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2>#!/usr/bin/perl<BR>open (FILE, "testfile\.txt") || die "Can't 
open&nbsp;input&nbsp;file !\n";<BR>@file = &lt;FILE&gt;;</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>open (FILEONE, 
"&gt;fileone\.txt") || die "Can't create file one !\n";<BR>open (FILETWO, 
"&gt;filetwo\.txt") || die "Can't create file two !\n";</FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>my($record) = 
split(/\n/, @file);<BR>foreach $record (@file)<BR>{<BR>&nbsp; my(@char) = 
split(//, $record);<BR>&nbsp; foreach $char ($record)<BR>&nbsp; 
{<BR>&nbsp;&nbsp; print FILEONE 
("@char[0]","~","@char[2]","~","@char[4]@char[6]","~","@char[8]@char[10]@char[12]","~","@char[14]\n");<BR>&nbsp;&nbsp; 
print FILETWO 
("@char[1]@char[3]@char[5]","~","@char[7]","~","@char[9]@char[11]","~","@char[13]@char[15]\n");<BR>&nbsp; 
}<BR>}<BR>close FILEONE;<BR>close FILETWO;<BR>close FILE;<BR>print ("Done 
!\n\a") &amp;&amp; die;</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff 
size=2>krgds</FONT></SPAN></DIV>
<DIV><SPAN class=048481105-13082003><FONT color=#0000ff size=2>Walter 
Kruse</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT size=2>-----Original 
  Message-----<BR><B>From:</B> Mark Hewitt 
  [mailto:mh2@isis.co.za]<BR><B>Sent:</B> 12 August 2003 11:17<BR><B>To:</B> 
  za-pm@mail.pm.org<BR><B>Subject:</B> Re: [Za-pm] flat file test 
  script<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>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...</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV>
  <BLOCKQUOTE 
  style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV style="FONT: 10pt arial"><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>----- Original Message ----- </DIV>
    <DIV style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><SPAN 
    class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>From:</STRONG> <A 
    title=WKruse@multichoice.co.za href="mailto:WKruse@multichoice.co.za">Walter 
    Kruse</A> </DIV>
    <DIV style="FONT: 10pt arial"><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>To:</STRONG> <A title=za-pm@mail.pm.org 
    href="mailto:za-pm@mail.pm.org">za-pm@mail.pm.org</A> </DIV>
    <DIV style="FONT: 10pt arial"><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Sent:</STRONG> Tuesday, August 12, 2003 
    1:58 PM</DIV>
    <DIV style="FONT: 10pt arial"><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Subject:</STRONG> [Za-pm] flat file 
    test script</DIV>
    <DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT 
    face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT face=Arial 
    size=2></FONT><FONT face=Arial size=2></FONT><BR>&nbsp;<SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN><SPAN 
    class=027012911-12082003><FONT size=2>Hi everyone - hope someone 
    will&nbsp;help a newbie</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>I need 
    to&nbsp;simulate the&nbsp;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 <SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>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&nbsp;1 again and so <SPAN 
    class=027012911-12082003><FONT size=2></FONT></SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2><SPAN class=027012911-12082003><FONT 
    size=2><SPAN class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>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&nbsp;as 
    I </FONT></SPAN></FONT></SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003></SPAN></FONT></SPAN></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003>Okay, a couple of 
points:</SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003>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?</SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003></SPAN></FONT></SPAN><SPAN 
    class=027012911-12082003><FONT size=2><SPAN class=027012911-12082003>2. What 
    do you mean by "db"? Another flat file, or a real SQL 
    database?</SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003></SPAN></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>specify. The 
    problem, I am faced with, however, is the counting and sorting of the chars. 
    I don't have a clue.&nbsp;This is as far as I got:</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>Try substr or 
    unpack.</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>From your desription, many 
    fields of specified length this sounds like a job for 
    unpack.</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>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:</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>@a = unpack( "A8 A4 
    A27");</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>You may want to generate 
    this string programatically is you have 88 fields to go in the 
    unpack!</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;.#!/usr/bin/perl<BR><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>open (FILE, "testfile") || die "Can't open file 
    !\n";<BR><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>@file = &lt;FILE&gt;;<BR><SPAN 
    class=027012911-12082003><FONT size=2></FONT></SPAN></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>my($record) = 
    split(/\n/, @file);</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>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 = &lt;file&gt; 
    statement.</FONT></SPAN><SPAN class=027012911-12082003><FONT 
  size=2></DIV></BLOCKQUOTE>
  <BLOCKQUOTE 
  style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>foreach $record (@file)<BR><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>{<BR><SPAN 
    class=027012911-12082003><FONT size=2></FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>&nbsp; my($char) = split(//, 
$record);<BR></DIV>
    <DIV><FONT face=Arial># You'll want to use substr/unpack here, followed by 
    the write to the database</FONT></DIV>
    <DIV><FONT face=Arial></FONT>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2>@a = unpack( "A8 A4 
    A27");</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    face=Arial></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    face=Arial></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial># this loop iterates 
    over all parameters in the last extraction and writes them alternatly (as 
    you showed in ur example) to the databases</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial># its scalable like 
    this and will handle any&nbsp; number of fields in the unpack 
    token</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>$i = 
    0;</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003>foreach $a&nbsp;(@a)</SPAN></DIV>
    <DIV><SPAN class=027012911-12082003>{</SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; if ( 
    $i++ &amp; 1 )</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;{</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp;add $a to 
    database 1</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003></SPAN><SPAN 
    class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
    }</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
    else</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
    {</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp; # add $a to database 2</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
    }</FONT></SPAN></DIV>
    <DIV><SPAN class=027012911-12082003>}&nbsp;</SPAN></DIV>
    <DIV> <BR><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>}<BR><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>close FILE;</DIV>
    <DIV><FONT face=Arial></FONT>&nbsp;</DIV>
    <DIV><FONT face=Arial></FONT>&nbsp;</DIV>
    <DIV><FONT face=Arial>Does this help you at all?</FONT></DIV>
    <DIV><FONT face=Arial></FONT>&nbsp;</DIV>
    <DIV><FONT face=Arial>Thanks,</FONT></DIV>
    <DIV><FONT face=Arial>Mark</FONT></DIV>
    <DIV><FONT 
    face=Arial>----------------------------------------------------------------------------<BR>Windows, 
    Linux and Internet Development Consultant</FONT></DIV>
    <DIV><FONT face=Arial>Email: <A 
    href="mailto:corporate@scriptsmiths.com">corporate@scriptsmiths.com</A><BR>Web: 
    <A 
    href="http://www.scriptsmiths.com">http://www.scriptsmiths.com</A></FONT></DIV>
    <DIV><FONT face=Arial>Cell: +27 82 
    9655295<BR>---------------------------------------------------------------------------</FONT></DIV>
    <DIV><FONT face=Arial></FONT></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT size=2></FONT></SPAN>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003></SPAN><FONT size=2><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>Kind 
    Regards<BR><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>Walter Kruse</FONT> <BR><FONT color=#0000ff 
    size=2><SPAN class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG><U>MultiChoice Information 
    Technology</U></STRONG></FONT> <BR><FONT color=#008000 size=2><SPAN 
    class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Software test 
    analyst</STRONG></FONT><FONT size=2><STRONG> - Application Delivery and 
    Support Team</STRONG></FONT> <BR><FONT color=#0000ff size=2><SPAN 
    class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Tel:<I>&nbsp;&nbsp;&nbsp;</I></STRONG></FONT><I> 
    <FONT color=#0000ff size=2>+27 (0) 11 289-4552</FONT><B></B></I> <BR><FONT 
    color=#0000ff size=2><SPAN class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Cell:</STRONG></FONT><I><STRONG>&nbsp;&nbsp;</STRONG> 
    <FONT color=#0000ff size=2>+27 (0) 82 660 7288</FONT></I> <BR><FONT 
    color=#0000ff size=2><SPAN class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Email:&nbsp;</STRONG></FONT><U> <FONT 
    color=#0000ff size=2>walterk@multichoice.co.za</FONT></U> <BR><FONT 
    color=#0000ff size=2><SPAN class=027012911-12082003><FONT color=#000000 
    size=2>&gt;&gt;</FONT></SPAN><STRONG>Personal web page:</STRONG></FONT><U> 
    <FONT color=#0000ff size=2><A href="http://www.ou-ryperd.net/" 
    target=_blank>http://www.ou-ryperd.net</A></FONT></U> </DIV>
    <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
    <DIV><SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>*********************************************************************************************************************<BR><SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>Everything in 
    this e-mail and attachments relating to the official business of 
    MultiChoice&nbsp;Africa is proprietary to the company. Any <SPAN 
    class=027012911-12082003><FONT size=2>&gt;&gt;</FONT></SPAN>view or opinion 
    expressed in this message may be the view of the individual and should not 
    automatically be ascribed to the <SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>company.&nbsp; If you are not the intended 
    recipient, you may not peruse, use, disseminate, distribute or copy this 
    message. If you have <SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>received this message in error, please notify 
    the sender immediately by email, facsimile or telephone and destroy the 
    original <SPAN class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>message.<BR><SPAN 
    class=027012911-12082003><FONT 
    size=2>&gt;&gt;</FONT></SPAN>*********************************************************************************************************************</DIV>
    <P>
    <HR>

    <P></P>_______________________________________________</BLOCKQUOTE></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <BLOCKQUOTE 
  style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV style="FONT: 10pt arial"><BR>Za-pm mailing 
    list<BR>Za-pm@mail.pm.org<BR>http://mail.pm.org/mailman/listinfo/za-pm<BR></DIV></BLOCKQUOTE></BLOCKQUOTE>
<DIV>*********************************************************************************************************************<BR>Everything 
in this e-mail and attachments relating to the official business of 
MultiChoice&nbsp;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.&nbsp; 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.<BR>*********************************************************************************************************************</DIV>
</BODY></HTML>