Data-SeaBASS
view release on metacpan or search on metacpan
lib/Data/SeaBASS.pm view on Meta::CPAN
# or
$sb_file->update([@row{'lat','lon','depth','chl'}]);
}
C<update> replaces the last row read (using C<next()>) with the input.
Caching must be enabled to use C<update>, C<set>, or C<insert>.
=cut
sub update {
my $self = shift;
if ( !$self->{'options'}{'cache'} ) {
croak("Caching must be enabled to write.");
} elsif ( $self->{'dataidx'} == -1 ) {
croak("No rows read yet.");
}
my $new_row = $self->ingest_row(@_);
unless ( defined($new_row) ) {
croak("Error parsing inputs");
}
$self->{'data'}[ $self->{'dataidx'} ] = $new_row;
} ## end sub update
=head2 set($index, \%data_row | \@data_row | $data_row | %data_row)
my %row = (lat => 1, lon => 2, chl => 1);
$sb_file->set(0, \%row);
print join(',',@{$sb_file->actual_fields()}); #lat,lon,chl
$sb_file->set(0, [1, 2, 1]);
lib/Data/SeaBASS.pm view on Meta::CPAN
} ## end sub set_delim
=head2 update_fields()
C<update_fields> runs through the currently cached rows and calls
C<add_and_remove_fields> on each row. It then updates the /fields and /units
headers in the header hash.
=cut
sub update_fields {
my ($self) = @_;
if ( $self->{'options'}{'cache'} && $self->{'max_dataidx'} >= 0 ) {
foreach my $hash ( @{ $self->{'data'} } ) {
$self->add_and_remove_fields($hash);
}
}
my $slash = ( $self->{'options'}{'keep_slashes'} ? '/' : '' );
$self->{'headers'}{"${slash}fields"} = join( ',', @{ $self->{'actual_fields'} } );
$self->{'headers'}{"${slash}units"} = join( ',', @{ $self->{'actual_units'} } );
} ## end sub update_fields
=head2 add_and_remove_fields(\%row)
Given a reference to a row, this function deletes any fields removed with
C<remove_field> and adds an undefined or /missing value for each field added
via C<add_field>. If C<missing_data_to_undef> is set, an undefined value is
given, otherwise, it is filled with the /missing value.
If C<fill_ancillary_data> is set, this function adds missing date, time,
date_time, lat, lon, and depth fields to the retrieved row from the header.
( run in 0.238 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )