/[cvs]/nfo/perl/libs/libp.pm
ViewVC logotype

Diff of /nfo/perl/libs/libp.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cvsjoko, Mon Jun 24 14:49:59 2002 UTC revision 1.3 by cvsjoko, Fri Jul 19 18:13:50 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.3  2002/07/19 18:13:50  cvsjoko
7    #  no message
8    #
9    #  Revision 1.2  2002/06/27 02:14:22  cvsjoko
10    #  + stripHtml stripSpaces stripNewLines toReal
11    #
12  #  Revision 1.1  2002/06/24 14:49:59  cvsjoko  #  Revision 1.1  2002/06/24 14:49:59  cvsjoko
13  #  + new  #  + new
14  #  #
# Line 14  package libp; Line 20  package libp;
20  require Exporter;  require Exporter;
21  @ISA = qw( Exporter );  @ISA = qw( Exporter );
22  @EXPORT = qw(  @EXPORT = qw(
23    Dumper      Dumper
24    md5 md5_hex md5_base64      md5 md5_hex md5_base64
25    ParseDate UnixDate      ParseDate UnixDate
26        strftime
27        stripHtml stripSpaces stripNewLines toReal trim
28        croak
29        array_getDifference
30  );  );
31    
32  use strict;  use strict;
# Line 28  use Digest::MD5 qw(md5 md5_hex md5_base6 Line 38  use Digest::MD5 qw(md5 md5_hex md5_base6
38  $main::TZ = 'GMT';  $main::TZ = 'GMT';
39  use Date::Manip;  use Date::Manip;
40    
41    require LWP::UserAgent;
42    use HTML::PullParser;
43    
44    # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
45    # see "perldoc -f localtime"
46    use POSIX qw(strftime);
47    
48    use Carp;
49    
50    
51    ########################################
52    
53    sub stripSpaces {
54      my $text = shift;
55      #print "text: $text", "\n";
56      #print "ord: ", ord(substr($text, 0, 1)), "\n";
57      $text =~ s/^\s*//g;
58      $text =~ s/\s*$//g;
59      return $text;
60    }
61    
62    sub trim {
63      my $string = shift;
64      return stripSpaces($string);
65    }
66    
67    sub stripNewLines {
68      my $text = shift;
69      #print "text: $text", "\n";
70      #print "ord: ", ord(substr($text, 0, 1)), "\n";
71      $text =~ s/\n//g;
72      #$text =~ s/\s*$//g;
73      return $text;
74    }
75    
76    sub toReal {
77      my $string = shift;
78      $string =~ m/(\d+\.*\d+)/;
79      my $real = $1;
80      return $real;
81    }
82    
83    sub stripHtml {
84      my $html = shift;
85      my $result = '';
86      #$html =~ s/<br>(.*)/ - ($1)/i;
87      my $p = HTML::PullParser->new(
88        doc => \$html,
89        text => 'text',
90        unbroken_text => 1,
91      );
92      while (my $token = $p->get_token()) {
93        my $text = join('', @{$token});
94        $result .= $text;
95      }
96      #$result =~ s/&nbsp;//g;
97      return $result;
98    }
99    
100    sub array_getRelations {
101      my $a_ref = shift;
102      my $b_ref = shift;
103      my @a = @{$a_ref};
104      my @b = @{$b_ref};
105    
106      my @isect = my @diff = my @union = ();
107      my $e;
108      my %count;
109      
110      foreach $e (@a, @b) { $count{$e}++ }
111    
112      foreach $e (keys %count) {
113          push(@union, $e);
114          push @{ $count{$e} == 2 ? \@isect : \@diff }, $e;
115      }
116      
117      my $result = {
118        union => \@union,
119        isect => \@isect,
120        diff => \@diff,
121      };
122    
123    }
124    
125    sub array_getDifference {
126      my $res = array_getRelations(shift, shift);
127      return $res->{diff};
128    }
129    
130  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed