Hello, Here is some code:
use DBI; # Load the DBI module + use CGI; # HTML + use strict; # keep it usable + use CGI qw(:standard); + use CGI::Carp qw( fatalsToBrowser ); + + + ### + my ($sth); + my ($ccode,@ccode); + my(@data,$data); + my ($p_str,@p_str); + my $i=0; # counter + my ($CC,@CC); + my ($po,@po); + my ($old,$new); + my (@old,@new); + my $count; + my $total; + my ($head_date,@head_date); + my $rts; + + open (CC,"ccchg.txt"); + while ($_=<CC>) { + push (@CC,$_); + ($old,$new)=split(/\|/,$_); + push @old,$old; + push @new,$new; + } + close (CC); + + + $i=0; + + while ($i<@new) { + print "old $old[$i] new $new[$i] "; + $i++; + } + + #print "$i - EYE \n"; + + ### Attributes to pass to DBI->connect() to disable automatic + ### error checking + my %attr = ( + PrintError => 0, + RaiseError => 0, + ); + + ### Perform the connection using the Informix driver + my $dbh = DBI->connect( "dbi:Informix:nps\@sumitt_aaa","xxx","yyyy" + ,\%attr )or die "Can't connect to database: ", $DBI::errstr, "\n"; + + $sth=$dbh->prepare("SELECT a.rts_nbr, a.ccode, b.orig_date + FROM rtsdet a, rtshead b + WHERE a.rts_nbr=b.rts_nbr + AND b.status MATCHES '[456OP]' + AND b.orig_date>'2002/01/01' + "); + # AND b.time_stamp>'2002-01-01 00:00:00' - using TIME STAMP + + $sth->execute(); + #print "old cc: $old \n"; + # will dump out all fields $data=$sth->dump_results(); + #$data=$sth->dump_results(); + + while ( ($po, $ccode,$head_date) = $sth->fetchrow_array() ){ + push @po,$po; + } + + print "$po \n"; + + $sth->finish; + + $sth=$dbh->prepare("SELECT rts_nbr,ccode FROM rtsdet + + WHERE ccode=? AND rts_nbr=?"); + + foreach $po(@po) { + for ($count=0;$count<@old;$count++) { + $sth->execute($old[$count],$po); + while ( ($rts,$data) = $sth->fetchrow_array() ){ + print "$po $rts $data $old[$count] $new[$coun +t] \n"; } + } + } + $sth->finish; + $p_str=@po; + print " POs: $p_str \n";
The first loop is a list of Purchase Orders (@po). The second loop is a specific code (@old). Basically this thing should go through and finds the POs that have one of these codes. $rts and $data would be the 2 elements from the SQL search. @new is an arra;y with new specific codes (matching the old on i.e. old->dog new->cat. Ultimately i want to replace those POs that have the old code with the new code. Will the above ONLY print out that criteria met by the SQL search? Or my loops to messy. I would like to use a 2 dimensional array (remeber DIM (10,10) from BASIC). And am not familiar with hashes. Any advice would be welcomed! Thanks, V
help?
He who laughs last, doesn't get the joke.

In reply to VVP:DBI, arrays and loops by vivekvp

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.