releasing/cbrtools/perl/TableFormatter/Csv.pm
author Ross Qin <ross.qin@nokia.com>
Tue, 30 Nov 2010 14:05:41 +0800
changeset 713 7b7f0409fc00
parent 602 3145852acc89
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
# TableFormatter/Csv.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
package TableFormatter::Csv;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use Utils;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use TableFormatter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use vars qw/@ISA/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
@ISA = qw(TableFormatter);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
sub PrintTable {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
  my $data = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
  my $location = Utils::PrependEpocRoot("\\epoc32\\relinfo\\temp-table.csv");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
  open(CSV, ">$location") or die "Couldn't open \"$location\" for writing because $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
  foreach my $row (@$data) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
    my $rowtext = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
    foreach my $cell (@$row) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
      $cell =~ s/\"/\\\"/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
      $cell =~ s/(.*)/\"$1\"/ if $cell =~ m/[\,\"]/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
      $rowtext .= $cell . ",";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
    chop $rowtext;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
    print CSV "$rowtext\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
  close CSV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
  system ($location);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
TableFormatter/Csv.pm - Formats tables in text
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
Creates a formatter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
=head2 PrintTable 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
Prints the table. Two arguments: firstly, a 2D array of the data. Secondly, a Boolean specifying whether the first row is a header row.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
The name of this file (i.e. Csv.pm) must be in that capitalisation, for IniData.pm to be able to find it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
No actual bugs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
 Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
=cut