The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::File::Map - Read data file definitions stored as XML

SYNOPSIS

    use Data::File::Map;

    # load data file definition

    $map = Data::File::Map->new_from_file( 'path/to/map.xml' );

    # read records from a data file using the map

    open FILE, 'data.txt' or die "Could not open file.";
    
    while( <FILE> ) {
        
        $record = $map->read( $_ );
        
    }
    
    close FILE;

DESCRIPTION

Data::File::Map will allow you to read in a data file definition stored as XML. The map can then be used to parse records in a data file. Handles delimited and formatted text data.

ATTRIBUTES

format

The format of the data file. Can be either csv for delimited files or 'text' for formatted ascii files.

isa: Str['text'|'csv']
default: csv
separator

Used to separate variables in a csv file. This is a regular expression.

isa: String['text'|'csv']
default: \|

METHODS

add_field \@attributes

Attribute order is name, position, width, label;

add_field $name, [\%attributes]

Add a field to the map. If \%attributes is supplied, the position, width, and label attributes will be stored.

fields [$want_objects]

Returns a list of ArrayRefs containing information about the fields in the definition. The format off the ArrayRefs is [$field_name, $position, $width]. Position and width will only be defined in text files. If $want_objects will return a list of Data::File::Map::Field objects.

field_names

Returns a list of field names in the order defined in the definition file.

get_field $name

Returns the Data::File::Map::Field object with the given name.

new

Create a new Data::File::Map instance.

new_from_file $path

Create a new Data::File::Map instance and load definition from a file.

new_from_string $string

Create a new Data::File::Map instance and load definition from a string.

parse_file $path

Load definition from a file.

parse_string $string

Load definition from a string.

read $line

Takes a line from a data file and uses the definition to extaract the variables. Returns a HashRef with field names as keys.

read_file $path

Calls read on each line in the given file and returns an array of records.

AUTHORS

Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>

COPYRIGHT

    Copyright (c) 2013 Jeffrey Ray Hallock.
    

LICENSE

This is free software, licensed under:

    The Artistic License 2.0 (GPL Compatible)