--- nfo/perl/libs/libp.pm 2002/06/27 02:14:22 1.2 +++ nfo/perl/libs/libp.pm 2002/07/19 18:13:50 1.3 @@ -1,8 +1,11 @@ ################################# # -# $Id: libp.pm,v 1.2 2002/06/27 02:14:22 cvsjoko Exp $ +# $Id: libp.pm,v 1.3 2002/07/19 18:13:50 cvsjoko Exp $ # # $Log: libp.pm,v $ +# Revision 1.3 2002/07/19 18:13:50 cvsjoko +# no message +# # Revision 1.2 2002/06/27 02:14:22 cvsjoko # + stripHtml stripSpaces stripNewLines toReal # @@ -17,11 +20,13 @@ require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( - Dumper - md5 md5_hex md5_base64 - ParseDate UnixDate - - stripHtml stripSpaces stripNewLines toReal + Dumper + md5 md5_hex md5_base64 + ParseDate UnixDate + strftime + stripHtml stripSpaces stripNewLines toReal trim + croak + array_getDifference ); use strict; @@ -36,6 +41,12 @@ require LWP::UserAgent; use HTML::PullParser; +# $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; +# see "perldoc -f localtime" +use POSIX qw(strftime); + +use Carp; + ######################################## @@ -48,6 +59,11 @@ return $text; } +sub trim { + my $string = shift; + return stripSpaces($string); +} + sub stripNewLines { my $text = shift; #print "text: $text", "\n"; @@ -81,4 +97,34 @@ return $result; } +sub array_getRelations { + my $a_ref = shift; + my $b_ref = shift; + my @a = @{$a_ref}; + my @b = @{$b_ref}; + + my @isect = my @diff = my @union = (); + my $e; + my %count; + + foreach $e (@a, @b) { $count{$e}++ } + + foreach $e (keys %count) { + push(@union, $e); + push @{ $count{$e} == 2 ? \@isect : \@diff }, $e; + } + + my $result = { + union => \@union, + isect => \@isect, + diff => \@diff, + }; + +} + +sub array_getDifference { + my $res = array_getRelations(shift, shift); + return $res->{diff}; +} + 1;