NAME
Data::Grid::Row - Row implementation for Data::Grid::Table
VERSION
Version 0.06
SYNOPSIS
# CSV files are themselves only a single table, so the list
# context assignment here takes the first and only one.
my ($table) = Data::Grid->parse('foo.csv')->tables;
while (my $row = $table->next) {
my @cells = $row->cells;
# or
@cells = @$row;
# or, if column names were supplied somehow:
my %cells = $row->as_hash;
# or
%cells = %$row;
}
METHODS
table
Retrieve the Data::Grid::Table object to which this row belongs. Alias for "parent" in Data::Grid::Container.
cells [$FLATTEN]
Retrieve the cells from the row, as an array in list context or arrayref in scalar context. The array dereferencing operator @{}
is also overloaded and works like this:
my @cells = @$row;
width
Returns the width of the row in columns. This is the same as scalar @{$row->cells}
.
as_hash [$FLATTEN]
If the table has a heading or its columns were designated in the constructor or with "columns" in Data::Grid::Table, this method will return the row as key-value pairs in list context and a HASH reference in scalar context. If there is no column spec, this method will generate dummy column names starting from 1, like col1
, col2
, etc. It will also fill in the blanks if the column spec is shorter than the actual row. If the column spec is longer, the overhang will be populated with undef
s. As well it is worth noting that duplicate keys will be clobbered with the rightmost value at this time, though that behaviour may change.
as_string
Returns the row as CSV, quoted where necessary, minus the newline.
AUTHOR
Dorian Taylor, <dorian at cpan.org>
SEE ALSO
COPYRIGHT & LICENSE
Copyright 2010-2018 Dorian Taylor.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.