<?xml version="1.0" encoding="windows-1252"?>
<node id="566896" title="Re: Variable/multiple matches using grep" created="2006-08-11 13:39:56" updated="2006-08-11 09:39:56">
<type id="11">
note</type>
<author id="195379">
idsfa</author>
<data>
<field name="doctext">
&lt;p&gt;I do not recommend using regular expressions to parse a CSV.  What happens if part of the input includes a comma? In the Massive Overkill department, I would suggest using [mod://DBD::CSV]:&lt;/p&gt;
&lt;code&gt;
   use DBI;
   $dbh = DBI-&gt;connect("DBI:CSV:")
       or die "Cannot connect: " . $DBI::errstr;
   $dbh-&gt;{'csv_tables'}-&gt;{'data'} = { 'file' =&gt; 'data.csv'};

   # Find the matching rows in the table
   $sth = $dbh-&gt;prepare('SELECT * FROM data ' .
                        'WHERE column1 = ? AND column2 = ? ' .
                        'AND column7 = ? AND column5 = ?', 
                        $one, $two, $three, $four)
        or die "Cannot prepare: " . $dbh-&gt;errstr();
   $sth-&gt;execute() or die "Cannot execute: " . $sth-&gt;errstr();

   my($id, $name);
   $sth-&gt;bind_columns(undef, \$id, \$name);
   while ($sth-&gt;fetch) 
   {
      # Print the name and id of each matching row
      printf("Found result row: id = %s, name = %s\n",
             defined($id) ? $id : "NULL",
             defined($name) ? $name : "NULL");
   }
   $sth-&gt;finish();
   $dbh-&gt;disconnect();
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-195379"&gt;
&lt;hr/&gt;
&lt;I&gt;The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. &amp;mdash; Cyrus H. Gordon&lt;/I&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
566876</field>
<field name="parent_node">
566876</field>
</data>
</node>
