The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

<!--  Presentation generated by Internet Assistant for Microsoft PowerPoint 97 -->

<HTML>
<HEAD>

<meta name="GENERATOR" content="Microsoft Internet Assistant for Microsoft PowerPoint 97">
 <TITLE>Our program for today...</TITLE> 
</HEAD>

<BODY     >

<CENTER>
<TABLE WIDTH=100%> 
     <TR> <TD WIDTH=100% ALIGN=CENTER>
         <A HREF="sld001.htm">First</A>&nbsp;&nbsp;
         <A HREF="sld060.htm">Previous</A>&nbsp;&nbsp;
         <A HREF="sld062.htm">Next</A>&nbsp;&nbsp;
         <A HREF="sld093.htm">Last</A>&nbsp;&nbsp;
&nbsp;&nbsp;         <A HREF="index.htm">Index</A>&nbsp;&nbsp;
         <A HREF="dbi.perl.org">Home</A>&nbsp;&nbsp;
         <A HREF="tsld061.htm">Text</A>&nbsp;&nbsp;
     </TD> </TR>
     <TR> <TD WIDTH=100% ALIGN=CENTER>
         <IMG SRC="img061.gif" usemap="#Objmap" WIDTH=800 HEIGHT=600 BORDER=0>
     </TD> </TR>
</TABLE>
<P>Slide 61 of 93</P>
</CENTER>
<!-- <UL>
<H2>Our program for today...</H2>
</UL></P>
<P><UL>
<H2>#!/usr/bin/perl -w
</H2>
</UL><UL>
<H2>use DBI;
</H2>
</UL><UL>
<H2>$dbh = DBI-&#062connect('', '', '', { RaiseError =&#062 1 });
</H2>
</UL><UL>
<H2>replace_price(split(/\s+/, $_)) while (&#060STDIN&#062);
</H2>
</UL><UL>
<H2>$dbh-&#062disconnect;
</H2>
</UL><UL>
<H2>
</H2>
</UL><UL>
<H2>sub replace_price {
</H2>
</UL><UL>
<H2>  my ($id, $price) = @_;
</H2>
</UL><UL>
<H2>  local $dbh-&#062{TraceLevel} = 1;
</H2>
</UL><UL>
<H2>  my $upd = $dbh-&#062prepare("UPDATE prices SET price=? WHERE id=?");
</H2>
</UL><UL>
<H2>  my $ins = $dbh-&#062prepare_cached("INSERT INTO prices (id,price) VALUES(?,?)");
</H2>
</UL><UL>
<H2>  my $rows = $upd-&#062execute($price, $id);
</H2>
</UL><UL>
<H2>  $ins-&#062execute($id, $price) if $rows == 0;
</H2>
</UL><UL>
<H2>}
</H2>
<UL>

<BR><BR>(The program is a little odd for the sake of producing a small trace output that can illustrate many concepts)</UL></UL></P>
<P>  -->
</Body>
</HTML>