# TeXLive::TLUtils.pm # common functions for TeX Live Infrastructure # # Copyright 2007 Norbert Preining # This file is licensed under the GNU General Public Licence version 2 # or any later version # # based on Fabrice Popineau's FileUtils.pm package TeXLive::TLUtils; =pod =head1 NAME TeXLive::TLUtils - utilities used in the TeX Live Infrastructure Modules =head1 SYNOPSIS use TeXLive::TLUtils; TeXLive::TLUtils::sort_uniq(@list); TeXLive::TLUtils::push_uniq(\@list, @items); TeXLive::TLUtils::member($item, @list); TeXLive::TLUtils::debug($string); =head1 DESCRIPTION =cut use File::Basename; BEGIN { use Exporter (); use Cwd; use File::Path; use vars qw( @ISA @EXPORT_OK ); @ISA = qw(Exporter); @EXPORT_OK = qw( &sort_uniq &push_uniq ); } =pod The C function sorts the given array and throws away multiple occurrences of elements. It returns a sorted and unified array. =cut sub sort_uniq { my (@l) = @_; my ($e, $f, @r); $f = ""; @l = sort(@l); foreach $e (@l) { if ($e ne $f) { $f = $e; push @r, $e; } } return @r; } =pod The C function pushes the last elements on the list referenced by the first argument. =cut sub push_uniq { # can't we use $l as a reference, and then use my? later ... local (*l, @le) = @_; foreach my $e (@le) { if (! &member($e, @l)) { push @l, $e; } } } =pod The C function returns true if the the first argument is contained in the list of the remaining arguments. =cut sub member { my ($e, @l) = @_; my ($f); foreach $f (@l) { if ($e eq $f) { return 1; } } return 0; } =pod The C function echos the argument string to STDERR in case that the global varialbe C is set. =cut sub debug { print STDERR @_ if ($::opt_debug); } 1; =pod =head1 AUTHORS AND COPYRIGHT This module and its documentation was written by Norbert Preining > for the TeX Live distribution and both are licensed under the GNU General Public License Version 2 or later. =head1 SEE ALSO The modules L, L, L, L, and the document L and the specification in the TeX Live repository trunk/Master/tlpkg/doc/. =cut ### Local Variables: ### perl-indent-level: 2 ### tab-width: 2 ### indent-tabs-mode: nil ### End: # vim:set tabstop=2: #