Max Maischein > List-Sliding-Changes-0.03 > List::Sliding::Changes

Download:
List-Sliding-Changes-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.03   Source  

NAME ^

List::Sliding::Changes - Extract new elements from a sliding window

SYNOPSIS ^

  use strict;
  use Tie::File;
  use List::Sliding::Changes qw(find_new_elements);

  my $filename = 'log.txt';
  my @log;
  tie @log, 'Tie::File', $filename
    or die "Couldn't tie to $filename : $!\n";

  # See what has happened since we last polled
  my @status = get_last_20_status_messages();

  # Find out what we did not already communicate
  my (@new) = find_new_elements(\@log,\@status);
  print "New log messages : $_\n"
    for (@new);

  # And update our log with what we have seen
  push @log, @new;

DESCRIPTION ^

This module allows you to easily find elements that were appended to one of two lists. It is intended to faciliate processing wherever you don't have a log but only a sliding window for events, such as a status window which only displays the 20 most recent events, without timestamp.

The module assumes that the update frequency is high and will always respect the longest overlap between the two sequences. To be a bit faster with long lists, it searches the first list from the end, assuming that the first list will be much longer than the second list.

PUBLIC METHODS ^

find_new_indices( \@OLDLIST, \@NEWLIST [, EQUALITY] )

Returns the list of indices that were added since the last time @OLDLIST was updated. This is convenient if you want to modify @NEWLIST afterwards. The function accepts an optional third parameter, which should be a reference to a function that takes two list elements and compares them for equality.

find_new_elements( \@OLDLIST, \@NEWLIST [, EQUALITY] )

Returns the list of the elements that were added since the last time @OLDLIST was updated.

BUGS ^

More tests are always welcome !

AUTHOR ^

  Max Maischein <corion@cpan.org>

COPYRIGHT ^

Copyright (c) 2003-2008 Max Maischein. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

perl(1), File::Tail for a solution working only with files, Text::Diff and Algorithm::Diff for a more holistic approach.

syntax highlighting: