1 |
################################# |
2 |
# |
3 |
# $Id: libp.pm,v 1.1 2002/06/24 14:49:59 cvsjoko Exp $ |
4 |
# |
5 |
# $Log: libp.pm,v $ |
6 |
# Revision 1.1 2002/06/24 14:49:59 cvsjoko |
7 |
# + new |
8 |
# |
9 |
# |
10 |
################################# |
11 |
|
12 |
package libp; |
13 |
|
14 |
require Exporter; |
15 |
@ISA = qw( Exporter ); |
16 |
@EXPORT = qw( |
17 |
Dumper |
18 |
md5 md5_hex md5_base64 |
19 |
ParseDate UnixDate |
20 |
|
21 |
stripHtml stripSpaces stripNewLines toReal |
22 |
); |
23 |
|
24 |
use strict; |
25 |
use warnings; |
26 |
|
27 |
use Data::Dumper; |
28 |
use Digest::MD5 qw(md5 md5_hex md5_base64); |
29 |
|
30 |
$main::TZ = 'GMT'; |
31 |
use Date::Manip; |
32 |
|
33 |
require LWP::UserAgent; |
34 |
use HTML::PullParser; |
35 |
|
36 |
|
37 |
######################################## |
38 |
|
39 |
sub stripSpaces { |
40 |
my $text = shift; |
41 |
#print "text: $text", "\n"; |
42 |
#print "ord: ", ord(substr($text, 0, 1)), "\n"; |
43 |
$text =~ s/^\s*//g; |
44 |
$text =~ s/\s*$//g; |
45 |
return $text; |
46 |
} |
47 |
|
48 |
sub stripNewLines { |
49 |
my $text = shift; |
50 |
#print "text: $text", "\n"; |
51 |
#print "ord: ", ord(substr($text, 0, 1)), "\n"; |
52 |
$text =~ s/\n//g; |
53 |
#$text =~ s/\s*$//g; |
54 |
return $text; |
55 |
} |
56 |
|
57 |
sub toReal { |
58 |
my $string = shift; |
59 |
$string =~ m/(\d+\.*\d+)/; |
60 |
my $real = $1; |
61 |
return $real; |
62 |
} |
63 |
|
64 |
sub stripHtml { |
65 |
my $html = shift; |
66 |
my $result = ''; |
67 |
#$html =~ s/<br>(.*)/ - ($1)/i; |
68 |
my $p = HTML::PullParser->new( |
69 |
doc => \$html, |
70 |
text => 'text', |
71 |
unbroken_text => 1, |
72 |
); |
73 |
while (my $token = $p->get_token()) { |
74 |
my $text = join('', @{$token}); |
75 |
$result .= $text; |
76 |
} |
77 |
#$result =~ s/ //g; |
78 |
return $result; |
79 |
} |
80 |
|
81 |
1; |