Public.Standards.CSV

[ Start > PikeModules > Module > Public.Standards.CSV ] [ Edit this Page | Viewing Version 1 ]


This module was made following http://en.wikipedia.org/wiki/Comma-separated_values

The examples shown below use the sample CSV file provided by the fore-mentionned documentation.

Files

Public.Standards.CSV.FILE() inherits from the buffered Stdio.FILE() class.

It sports two important methods:

  • int write_row(mixed… row)
  • int|array read_row()

Reading

The method-way:

object infile = Public.Standards.CSV.FILE("/tmp/sample.csv", "r");
infile->read_row();
(1) Result: ({ /* 5 elements */
                "1997",
                "Ford",
                "E350",
                "ac, abs, moon",
                "3000.00"
            })

The iterator-way:

object infile = Public.Standards.CSV.FILE("/tmp/sample.csv", "r");
foreach(infile; int line_number; array data) {
//...
}

Writing

object outfile = Public.Standards.CSV.FILE("/tmp/foo.csv", "cw");
outfile->write_row("foo","bar","baz");
(1) Result: 13

Powered by PikeWiki2

 
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University