I solved the problem by changing the format of the flat file slightly. I now use the term END after each component and this allowed me to delete the offending code.

The code works as it should now. After a good nights sleep.
#! perl -w scipt use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; my ($data_source, $database, $user_id, $password) = qw( *********** ** +******** ********** ******* ); my $conn_string = "driver={SQL Server}; Server=$data_source; Database= +$database; Trusted_Connection=yes"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my $Request_id; my $Variable_number; my $Variable; my $Choice; my @VARIABLE; my @CHOICE; my $Command; my $Return_results; my $Component_number_old = 1; my $Component_number = 1; my $SPROC; my $unique; my $elements_in_array; my $flat_file = "Flat_file.txt"; open (FLAT_FILE, "<$flat_file"); while (<FLAT_FILE>){ chomp; $Component_number_old = $Component_number; if ($_ =~ /SPROC\sName\:\s([a-z|A-Z|0-9|_]{1,100})/){ print "Hi_A\n"; $SPROC = $1; } elsif ($_ =~ /^\*(.{36})\;(\d{1,5})\;(\d{1,5})\;([a-z|A-Z|0-9|_]{1,5 +0})\;(.{1,100})/){ print "$_\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); print "Hi_B\n"; $unique = $1; $Component_number = $2; $elements_in_array = $3; $Variable = $4; $Choice = $5; } if ($_ =~ /^\sEND/){ print "Hi_E\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); $Command = join(' ', 'EXEC', $SPROC, join(', ', @CHOICE[1 .. $elements_in_array])) . ';'; my $Request_id = $CHOICE[26]; print "$Command\n"; Got_Command($Command, $Request_id); undef @CHOICE; my @CHOICE; } } close FLAT_FILE; my $source = $flat_file; my $dest = 'Bin'; move($source, $dest) or die "Error moving file: $!\n"; sub Got_Command { my($Command,$Request_id) = @_; my $output_file = "Output/Output_file_".$Request_id.".txt"; open (OUTPUT_FILE, "+>>$output_file"); print "$Command\n"; my $sthB_A = $dbh->prepare($Command) or die "Couldn't prepare query +: ".$dbh->errstr; $sthB_A->execute() or die "Couldn't execute query: ".$sthB_A->errstr +; my $Return_results = "Select * from Result_storage_keep where Unique +_identifier = ".$Request_id."\;"; print "$Return_results\n"; my $sth = $dbh->prepare($Return_results) or die "Couldn't prepare qu +ery: ".$dbh->errstr; $sth->execute() or die "Couldn't execute query: ".$sth->errstr; while (my @row = $sth->fetchrow_array ) { print OUTPUT_FILE join("\t", @row); print OUTPUT_FILE "\n"; } }

In reply to Re^4: Flat file handling by Win
in thread Flat file handling by Win

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.