title: Script for updating DB
body: <p>I have the following piece of perl script for updating Oracle Database. It's working perfectly fine; but, I want to know how to simplify this script: </p>
  
  <pre><code>use DBI;
  my $dbh;
  my $bad_form = "text.txt";
  
  open (OUT, $bad_form) or die "Could not open $bad_form";
  while (&lt;OUT&gt;){
      chomp $_;
      my ($item_id, $description, $form_id_1, $form_id_3) = split(/\|/, $_);
  
      my $new_form_id_1 = form_1($form_id_1);
      my $new_form_id_3 = form_3($form_id_3);
  
      if ( $new_form_id_1 ne 'null' ){
              my $sql = "update item_table set form_id_1 = '$new_form_id_1' where item_id = '$item_id'";
              my $item = $dbh-&gt;prepare($sql) or (log_error("Couldn't prepare statement: " . $dbh-&gt;errstr) and return 2);
              $item-&gt;execute() or (log_error("Couldn't execute statement: " . $item-&gt;errstr) and return 2);
      }else{
              $form_id_1 = "correct value";
              $new_form_id_1 = "no updated";
      }
  
      if ( $new_form_id_3 ne 'null' ){
              my $sql = "update item_table set form_id_3 = '$new_form_id_3' where item_id = '$item_id'";
              my $item = $dbh-&gt;prepare($sql) or (log_error("Couldn't prepare statement: " . $dbh-&gt;errstr) and return 2);
              $item-&gt;execute() or (log_error("Couldn't execute statement: " . $item-&gt;errstr) and return 2);
  
      }else{
              $form_id_3 = "correct value";
              $new_form_id_3 = "no updated";
      }
  }
  </code></pre>
  
  <p>Where function form_1() and form_3() are used to generated new value for form_id_1,3.</p>
  
  <p>Any help would be appreciated. Thank you a lot for your help. </p>