lib/Text/CSV.pm
author Simon Howkins <simonh@symbian.org>
Thu, 13 May 2010 16:27:37 +0100
changeset 267 2251fde91223
permissions -rw-r--r--
Changed script to use CSV formatted input, rather than TSV. This means that the script can directly process the CSV downloaded from Bugzilla, without any need to use Excel to convert it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
267
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
package Text::CSV;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 1997 Alan Citterman. All rights reserved.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
# This program is free software; you can redistribute it and/or
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     5
# modify it under the same terms as Perl itself.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     6
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     7
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
# HISTORY
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
# Written by:
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
#    Alan Citterman <alan@mfgrtl.com>
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    12
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    13
# Version 0.01  06/05/1997
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
#    original version
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
# Version 0.02x  13/05/2010
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
#    Hacked at symbian.org to permit top bit set characters in CSV
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
require 5.002;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
use strict;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
BEGIN {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
#  use Exporter   ();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
#  use AutoLoader qw(AUTOLOAD);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
  use vars       qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
  $VERSION =     '0.02x';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
#  @ISA =         qw(Exporter AutoLoader);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
  @EXPORT =      qw();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
  @EXPORT_OK =   qw();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
  %EXPORT_TAGS = qw();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
# version
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
#    class/object method expecting no arguments and returning the version number
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
#    of Text::CSV.  there are no side-effects.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
sub version {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
  return $VERSION;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
# new
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
#    class/object method expecting no arguments and returning a reference to a
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
#    newly created Text::CSV object.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    52
sub new {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    53
  my $proto = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    54
  my $class = ref($proto) || $proto;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
  my $self = {};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    56
  $self->{'_STATUS'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    57
  $self->{'_ERROR_INPUT'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    58
  $self->{'_STRING'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
  $self->{'_FIELDS'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
  bless $self, $class;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
  return $self;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    62
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    63
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    65
# status
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    66
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    67
#    object method returning the success or failure of the most recent combine()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    68
#    or parse().  there are no side-effects.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    69
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
sub status {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    71
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    72
  return $self->{'_STATUS'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    75
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    76
# error_input
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
#    object method returning the first invalid argument to the most recent
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
#    combine() or parse().  there are no side-effects.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
sub error_input {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    82
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    83
  return $self->{'_ERROR_INPUT'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    84
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    86
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    87
# string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    88
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
#    object method returning the result of the most recent combine() or the
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    90
#    input to the most recent parse(), whichever is more recent.  there are no
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
#    side-effects.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
sub string {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    94
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
  return $self->{'_STRING'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    96
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
# fields
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   101
#    object method returning the result of the most recent parse() or the input
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   102
#    to the most recent combine(), whichever is more recent.  there are no
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
#    side-effects.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   104
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
sub fields {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
  if (ref($self->{'_FIELDS'})) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
    return @{$self->{'_FIELDS'}};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
  return undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   112
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   113
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
# combine
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   115
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   116
#    object method returning success or failure.  the given arguments are
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
#    combined into a single comma-separated value.  failure can be the result of
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   118
#    no arguments or an argument containing an invalid character.   side-effects
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
#    include:
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
#      setting status()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
#      setting fields()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
#      setting string()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
#      setting error_input()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
sub combine {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
  my @part = @_;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
  $self->{'_FIELDS'} = \@part;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
  $self->{'_ERROR_INPUT'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
  $self->{'_STATUS'} = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
  $self->{'_STRING'} = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   132
  my $column = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
  my $combination = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
  my $skip_comma = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
  if ($#part >= 0) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   136
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
    # at least one argument was given for "combining"...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
    for $column (@part) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
#      if ($column =~ /[^\t\040-\176]/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   141
#	# an argument contained an invalid character...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   142
#	$self->{'_ERROR_INPUT'} = $column;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   143
#	return $self->{'_STATUS'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   144
#      }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
      if ($skip_comma) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   146
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   147
	# do not put a comma before the first argument...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   148
	$skip_comma = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   149
      } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   150
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
	# do put a comma before all arguments except the first argument...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   152
	$combination .= ',';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
      }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   154
      $column =~ s/\042/\042\042/go;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
      $combination .= "\042";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
      $combination .= $column;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   157
      $combination .= "\042";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   158
    }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   159
    $self->{'_STRING'} = $combination;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   160
    $self->{'_STATUS'} = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   161
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   162
  return $self->{'_STATUS'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   163
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   164
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   165
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   166
# parse
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   167
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   168
#    object method returning success or failure.  the given argument is expected
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   169
#    to be a valid comma-separated value.  failure can be the result of
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   170
#    no arguments or an argument containing an invalid sequence of characters.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   171
#    side-effects include:
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   172
#      setting status()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   173
#      setting fields()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   174
#      setting string()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   175
#      setting error_input()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   176
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   177
sub parse {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   178
  my $self = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   179
  $self->{'_STRING'} = shift;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   180
  $self->{'_FIELDS'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   181
  $self->{'_ERROR_INPUT'} = $self->{'_STRING'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   182
  $self->{'_STATUS'} = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   183
  if (!defined($self->{'_STRING'})) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   184
    return $self->{'_STATUS'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   185
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   186
  my $keep_biting = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   187
  my $palatable = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   188
  my $line = $self->{'_STRING'};
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   189
  if ($line =~ /\n$/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   190
    chop($line);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   191
    if ($line =~ /\r$/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   192
      chop($line);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   193
    }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   194
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   195
  my $mouthful = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   196
  my @part = ();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   197
  while ($keep_biting and ($palatable = $self->_bite(\$line, \$mouthful, \$keep_biting))) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   198
    push(@part, $mouthful);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   199
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   200
  if ($palatable) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   201
    $self->{'_ERROR_INPUT'} = undef;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   202
    $self->{'_FIELDS'} = \@part;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   203
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   204
  return $self->{'_STATUS'} = $palatable;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   205
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   206
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   207
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   208
# _bite
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   209
#
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   210
#    *private* class/object method returning success or failure.  the arguments
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   211
#    are:
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   212
#      - a reference to a comma-separated value string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   213
#      - a reference to a return string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   214
#      - a reference to a return boolean
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   215
#    upon success the first comma-separated value of the csv string is
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   216
#    transferred to the return string and the boolean is set to true if a comma
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   217
#    followed that value.  in other words, "bite" one value off of csv
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   218
#    returning the remaining string, the "piece" bitten, and if there's any
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   219
#    more.  failure can be the result of the csv string containing an invalid
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   220
#    sequence of characters.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   221
#   
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   222
#    from the csv string and 
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   223
#    to be a valid comma-separated value.  failure can be the result of
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   224
#    no arguments or an argument containing an invalid sequence of characters.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   225
#    side-effects include:
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   226
#      setting status()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   227
#      setting fields()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   228
#      setting string()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   229
#      setting error_input()
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   230
################################################################################
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   231
sub _bite {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   232
  my ($self, $line_ref, $piece_ref, $bite_again_ref) = @_;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   233
  my $in_quotes = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   234
  my $ok = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   235
  $$piece_ref = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   236
  $$bite_again_ref = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   237
  while (1) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   238
    if (length($$line_ref) < 1) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   239
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   240
      # end of string...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   241
      if ($in_quotes) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   242
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   243
	# end of string, missing closing double-quote...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   244
	last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   245
      } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   246
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   247
	# proper end of string...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   248
	$ok = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   249
	last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   250
      }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   251
    } elsif ($$line_ref =~ /^\042/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   252
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   253
      # double-quote...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   254
      if ($in_quotes) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   255
	if (length($$line_ref) == 1) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   256
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   257
	  # closing double-quote at end of string...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   258
	  substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   259
	  $ok = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   260
	  last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   261
	} elsif ($$line_ref =~ /^\042\042/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   262
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   263
	  # an embedded double-quote...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   264
	  $$piece_ref .= "\042";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   265
	  substr($$line_ref, 0, 2) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   266
	} elsif ($$line_ref =~ /^\042,/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   267
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   268
	  # closing double-quote followed by a comma...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   269
	  substr($$line_ref, 0, 2) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   270
	  $$bite_again_ref = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   271
	  $ok = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   272
	  last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   273
	} else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   274
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   275
	  # double-quote, followed by undesirable character (bad character sequence)...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   276
	  last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   277
	}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   278
      } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   279
	if (length($$piece_ref) < 1) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   280
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   281
	  # starting double-quote at beginning of string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   282
	  $in_quotes = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   283
	  substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   284
	} else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   285
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   286
	  # double-quote, outside of double-quotes (bad character sequence)...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   287
	  last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   288
	}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   289
      }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   290
    } elsif ($$line_ref =~ /^,/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   291
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   292
      # comma...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   293
      if ($in_quotes) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   294
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   295
	# a comma, inside double-quotes...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   296
	$$piece_ref .= substr($$line_ref, 0 ,1);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   297
	substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   298
      } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   299
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   300
	# a comma, which separates values...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   301
	substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   302
	$$bite_again_ref = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   303
	$ok = 1;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   304
	last;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   305
      }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   306
    } elsif ($$line_ref =~ /^[\t\040-\176]/) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   307
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   308
      # a tab, space, or printable...
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   309
      $$piece_ref .= substr($$line_ref, 0 ,1);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   310
      substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   311
    } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   312
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   313
      # an undesirable character... But use it anyway
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   314
      $$piece_ref .= substr($$line_ref, 0 ,1);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   315
      substr($$line_ref, 0, 1) = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   316
    }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   317
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   318
  return $ok;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   319
}
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   320
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   321
=head1 NAME
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   322
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   323
Text::CSV - comma-separated values manipulation routines
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   324
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   325
=head1 SYNOPSIS
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   326
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   327
 use Text::CSV;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   328
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   329
 $version = Text::CSV->version();      # get the module version
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   330
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   331
 $csv = Text::CSV->new();              # create a new object
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   332
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   333
 $status = $csv->combine(@columns);    # combine columns into a string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   334
 $line = $csv->string();               # get the combined string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   335
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   336
 $status = $csv->parse($line);         # parse a CSV string into fields
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   337
 @columns = $csv->fields();            # get the parsed fields
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   338
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   339
 $status = $csv->status();             # get the most recent status
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   340
 $bad_argument = $csv->error_input();  # get the most recent bad argument
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   341
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   342
=head1 DESCRIPTION
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   343
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   344
Text::CSV provides facilities for the composition and decomposition of
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   345
comma-separated values.  An instance of the Text::CSV class can combine
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   346
fields into a CSV string and parse a CSV string into fields.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   347
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   348
=head1 FUNCTIONS
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   349
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   350
=over 4
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   351
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   352
=item version
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   353
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   354
 $version = Text::CSV->version();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   355
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   356
This function may be called as a class or an object method.  It returns the current
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   357
module version.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   358
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   359
=item new
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   360
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   361
 $csv = Text::CSV->new();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   362
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   363
This function may be called as a class or an object method.  It returns a reference to a
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   364
newly created Text::CSV object.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   365
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   366
=item combine
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   367
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   368
 $status = $csv->combine(@columns);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   369
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   370
This object function constructs a CSV string from the arguments, returning
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   371
success or failure.  Failure can result from lack of arguments or an argument
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   372
containing an invalid character.  Upon success, C<string()> can be called to
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   373
retrieve the resultant CSV string.  Upon failure, the value returned by
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   374
C<string()> is undefined and C<error_input()> can be called to retrieve an
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   375
invalid argument.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   376
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   377
=item string
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   378
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   379
 $line = $csv->string();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   380
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   381
This object function returns the input to C<parse()> or the resultant CSV string of
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   382
C<combine()>, whichever was called more recently.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   383
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   384
=item parse
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   385
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   386
 $status = $csv->parse($line);
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   387
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   388
This object function decomposes a CSV string into fields, returning
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   389
success or failure.  Failure can result from a lack of argument or the given CSV
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   390
string is improperly formatted.  Upon success, C<fields()> can be called to
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   391
retrieve the decomposed fields .  Upon failure, the value returned by
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   392
C<fields()> is undefined and C<error_input()> can be called to retrieve the
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   393
invalid argument.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   394
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   395
=item fields
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   396
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   397
 @columns = $csv->fields();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   398
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   399
This object function returns the input to C<combine()> or the resultant decomposed
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   400
fields of C<parse()>, whichever was called more recently.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   401
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   402
=item status
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   403
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   404
 $status = $csv->status();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   405
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   406
This object function returns success (or failure) of C<combine()> or C<parse()>,
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   407
whichever was called more recently.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   408
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   409
=item error_input
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   410
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   411
 $bad_argument = $csv->error_input();
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   412
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   413
This object function returns the erroneous argument (if it exists) of C<combine()>
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   414
or C<parse()>, whichever was called more recently.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   415
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   416
=back
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   417
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   418
=head1 EXAMPLE
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   419
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   420
  require Text::CSV;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   421
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   422
  my $csv = Text::CSV->new;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   423
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   424
  my $column = '';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   425
  my $sample_input_string = '"I said, ""Hi!""",Yes,"",2.34,,"1.09"';
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   426
  if ($csv->parse($sample_input_string)) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   427
    my @field = $csv->fields;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   428
    my $count = 0;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   429
    for $column (@field) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   430
      print ++$count, " => ", $column, "\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   431
    }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   432
    print "\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   433
  } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   434
    my $err = $csv->error_input;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   435
    print "parse() failed on argument: ", $err, "\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   436
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   437
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   438
  my @sample_input_fields = ('You said, "Hello!"',
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   439
			     5.67,
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   440
			     'Surely',
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   441
			     '',
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   442
			     '3.14159');
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   443
  if ($csv->combine(@sample_input_fields)) {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   444
    my $string = $csv->string;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   445
    print $string, "\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   446
  } else {
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   447
    my $err = $csv->error_input;
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   448
    print "combine() failed on argument: ", $err, "\n";
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   449
  }
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   450
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   451
=head1 CAVEATS
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   452
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   453
This module is based upon a working definition of CSV format which may not be
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   454
the most general.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   455
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   456
=over 4
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   457
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   458
=item 1 
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   459
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   460
Allowable characters within a CSV field include 0x09 (tab) and the inclusive
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   461
range of 0x20 (space) through 0x7E (tilde).
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   462
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   463
=item 2
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   464
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   465
A field within CSV may be surrounded by double-quotes.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   466
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   467
=item 3
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   468
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   469
A field within CSV must be surrounded by double-quotes to contain a comma.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   470
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   471
=item 4
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   472
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   473
A field within CSV must be surrounded by double-quotes to contain an embedded
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   474
double-quote, represented by a pair of consecutive double-quotes.
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   475
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   476
=item 5
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   477
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   478
A CSV string may be terminated by 0x0A (line feed) or by 0x0D,0x0A
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   479
(carriage return, line feed).
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   480
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   481
=head1 AUTHOR
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   482
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   483
Alan Citterman F<E<lt>alan@mfgrtl.comE<gt>>
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   484
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   485
=head1 SEE ALSO
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   486
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   487
perl(1)
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   488
2251fde91223 Changed script to use CSV formatted input, rather than TSV.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   489
=cut