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

NAME

Data::Range::Compare::Stream::Iterator::File - simple File iterator

SYNOPSIS

  use Data::Range::Compare::Stream;
  use Data::Range::Compare::Stream::Iterator::File;

  my $iterator=Data::Range::Compare::Stream::Iterator::File->new(
    filename=>'some_file.csv',
  );

  while($iterator->has_next) {
    my $next_range=$iterator->get_next;
    print $next_range,"\n";
  }

DESCRIPTION

This module implements a very simple file iterator interface. This iterator interface assumes that the data is pre-sorted. The result objects returned are ranges: The class the objects are constructed from is determined by $iterator->NEW_FROM. Parsing is handled by $iterator->parse_line.

OO Methods

  • my $iterator=new Data::Range::Compare::Stream::Iterator::File;

    Instance Constructor, all arguments are optional

        Arguments:
    
          filename=>'source_file.csv'  
            # the file is assumed to be an absolute or relative path to the file location.
  • if($iterator->in_error) { ... }

    Returns true if there was a problem opening the file.

  • my $class=$iterator->NEW_FROM;

    $class will contain the name of the class new ranges are to be constructed from: This will need to be overloaded if the class is not "Data::Range::Compare::Stream".

  • my $ref=$self->parss_line($line);

    This is the actual parser interface: $ref is an anonymous array representing the constructor arguments to be passed to the class referee to via $iterator->NEW_FROM.

    The parser logic is very simple and can be described as follows.

        sub parse_line {
          my ($self,$line)=@_;
          chomp $line;
          return [split /\s+/,$line];
        }

    If the data you are dealing with is not parse-able using the above code then you will need to extend this package and overload the $iterator->parse_line interface.

  • while($iterator->has_next) { do something }

    Returns true when there are more rows to fetch.

  • my $range=$iterator->get_next;

    Returns the next $range from the given source file.

SEE ALSO

Data::Range::Compare::Stream::Cookbook

AUTHOR

Michael Shipper

Source-Forge Project

As of version 0.001 the Project has been moved to Source-Forge.net

Data Range Compare https://sourceforge.net/projects/data-range-comp/

COPYRIGHT

Copyright 2011 Michael Shipper. All rights reserved.

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