View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Curtis "Ovid" Poe > Data-Record > Data::Record



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.02   Source  


Data::Record - "split" on steroids


Version 0.02


  use Regexp::Common;
  use Data::Record;
  my $record = Data::Record->new({
    split  => "\n",
    unless => $RE{quoted},
  my @data = $record->records($data);


Sometimes we need data split into records and a simple split on the input record separator ($/) or some other value fails because the values we're splitting on may allowed in other parts of the data. Perhaps they're quoted. Perhaps they're embedded in other data which should not be split up.

This module allows you to specify what you wish to split the data on, but also speficy an "unless" regular expression. If the text in question matches the "unless" regex, it will not be split there. This allows us to do things like split on newlines unless newlines are embedded in quotes.



Common usage:

 my $record = Data::Record->new({
    split  => qr/$split/,
    unless => qr/$unless/,

Advanced usage:

 my $record = Data::Record->new({
    split  => qr/$split/,
    unless => qr/$unless/,  # optional
    token  => $token,       # optional
    chomp  => 0,            # optional
    limit  => $limit,       # optional (do not use with trim)
    trim   => 1,            # optional (do not use with limit)
    fields => {
        split  => ',',
        unless => $RE{quoted}, # from Regexp::Common

The constructor takes a hashref of key/value pairs to set the behavior of data records to be created.


  my $split = $record->split;

Getter/setter for split value. May be a regular expression or a scalar value.


 my $unless = $self->unless;

Getter/setter for unless value. May be a regular expression or a scalar value.


  my $chomp = $record->chomp;

Getter/setter for boolean chomp value.


  my $limit = $record->limit;

Getter/setter for integer limit value.


  my $trim = $record->trim;

Getter/setter for boolean limit value. Setting this value will cause any previous limit value to be overwritten.


  my $token = $record->token;

Getter/setter for token value. Token must be a string that does not match the split value and is not found in the text.

You can return the current token value if you have set it in your code. If you rely on this module to create a token (this is the normal behavior), it is not available via this method until records is called.

Setting the token to an undefined value causes Data::Record to try and find a token itself.

If the token matches the split value, this method will croak when you attempt to set the token.

If the token is found in the data, the records method will croak when it is called.


  my @records = $record->records($data);

Returns @records for $data based upon current split criteria.


It's possible to get erroneous results if the split value is /\d+/. I've tried to work around this. Please let me know if there is a problem.


This module must read all of the data at once. This can make it slow for larger data sets.


Curtis "Ovid" Poe, <ovid [at] cpan [dot] org>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


Thanks to the Monks for inspiration from

0.02 Thanks to Smylers and Stefano Rodighiero for catching POD errors.


Copyright 2005 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: