vivekvp has asked for the wisdom of the Perl Monks concerning the following question:
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, Vuse 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";
He who laughs last, doesn't get the joke.help?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: VVP:DBI, arrays and loops
by lachoy (Parson) on Mar 23, 2002 at 00:20 UTC | |
|
Re: VVP:DBI, arrays and loops
by vladb (Vicar) on Mar 23, 2002 at 00:07 UTC |