<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Hello List,<DIV><BR class="khtml-block-placeholder"></DIV><DIV>I am starting on Erlang. I read most of the new Erlang book. However, I am lost with something really simple and probably stupid.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I am reading a file, line by line.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Each line is in the form</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>"a_code" , a_date</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The quotes (") are present in the file, as well as the comma. For example:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>"C51CBA979E4311D67900201842D2EEE81",2003-08-07<BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I would like to cut the string into pieces (to be able to modify it...). Again, this is a test to learn Erlang, I know how to do this in two lines of Ruby :-). I could also probably use a built in function to parse the string. But I would like to understand pattern matching and lists.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>So I wrote this, first read the file:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>start() -></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">    </SPAN>case <A href="file:open">file:open</A>("ENRL_ENROLLMENT.csv",read) of</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">             </SPAN>{ok, S} <SPAN class="Apple-tab-span" style="white-space:pre">    </SPAN>-> </DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                               </SPAN>Val = do_read(S),</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                            </SPAN><A href="file:close">file:close</A>(S),</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                                </SPAN>Result = process_lines(Val),</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                         </SPAN>{ok,Result};</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">              </SPAN>{error, Why} <SPAN class="Apple-tab-span" style="white-space:pre">       </SPAN>-> </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                            </SPAN>{error, Why}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">      </SPAN>end.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Then the lines:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>do_read(S) -></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN>case io:get_line(S,'') of</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">         </SPAN>eof<SPAN class="Apple-tab-span" style="white-space:pre">         </SPAN>-> [];</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">            </SPAN>Line <SPAN class="Apple-tab-span" style="white-space:pre">               </SPAN>-> [Line | do_read(S)]</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>end.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Then process each line in the list of lines:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>process_lines(Lines) -></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">    </SPAN>[Date || [_Code | "," ++ Date] <- Lines].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Something is wrong, because it compiles but here is what I get:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>11> c(csv_convert.erl). </DIV><DIV>{ok,csv_convert}</DIV><DIV>12> csv_convert:start().</DIV><DIV>{ok,[]}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>If each line is actually a list of characters, why can't I match the pattern I want???</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Thanks for any hint (or examples) !!</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Alex</DIV><DIV>--</DIV><DIV>Alexander Lamb</DIV><DIV>Founding Associate</DIV><DIV>RODANOTECH Sàrl</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>4 ch. de la Tour de Champel</DIV><DIV>1206 Geneva</DIV><DIV>Switzerland</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Tel:  022 347 77 37</DIV><DIV>Fax: 022 347 77 38</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><A href="http://www.rodanotech.ch">http://www.rodanotech.ch</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV></SPAN></SPAN><BR class="Apple-interchange-newline"></SPAN> </DIV><BR></DIV></BODY></HTML>