(.*?)<\/table>/)
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
|
|
|
my $data = $1; |
40
|
0
|
|
|
|
|
|
$data =~ s/^\s+//; |
41
|
0
|
|
|
|
|
|
$data =~ s/\s+$//; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my @units = (); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
while ($data =~ / |
(.*?)<\/tr>/g)
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
|
my $unit = $1; |
48
|
0
|
0
|
|
|
|
|
if($unit =~ |
49
|
|
|
|
|
|
|
/(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>.*?(.*?)<\/span>/) |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
|
|
|
my $station_info = |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
station_name => $1, |
54
|
|
|
|
|
|
|
station_address => "$2, $3", |
55
|
|
|
|
|
|
|
unleaded_price => $4, |
56
|
|
|
|
|
|
|
unleaded_date => $5, |
57
|
|
|
|
|
|
|
plus_price => $6, |
58
|
|
|
|
|
|
|
plus_date => $7, |
59
|
|
|
|
|
|
|
premium_price => $8, |
60
|
|
|
|
|
|
|
premium_date => $9, |
61
|
|
|
|
|
|
|
diesel_price => $10, |
62
|
|
|
|
|
|
|
diesel_date => $11 |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
$station_info->{unleaded_price} = $1 |
67
|
|
|
|
|
|
|
if ($station_info->{unleaded_price} =~ |
68
|
|
|
|
|
|
|
/\$(.*)/); |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
$station_info->{plus_price} = $1 |
71
|
|
|
|
|
|
|
if ($station_info->{plus_price} =~ |
72
|
|
|
|
|
|
|
/\$(.*)/); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$station_info->{premium_price} = $1 |
75
|
|
|
|
|
|
|
if ($station_info->{premium_price} =~ |
76
|
|
|
|
|
|
|
/\$(.*)/); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
$station_info->{diesel_price} = $1 |
79
|
|
|
|
|
|
|
if ($station_info->{diesel_price} =~ |
80
|
|
|
|
|
|
|
/\$(.*)/); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
push @units, $station_info; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self->{units} = \@units; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#use Data::Dumper; |
89
|
|
|
|
|
|
|
#print Dumper @units; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
return undef; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_stations |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
return $self->{units}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_cheapest_station |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
105
|
0
|
|
|
|
|
|
my $type = shift; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @units = @{$self->{units}}; |
|
0
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $lowest_price = undef; |
110
|
0
|
|
|
|
|
|
my $cheapest_station = undef; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
foreach(@units) |
114
|
|
|
|
|
|
|
{ |
115
|
0
|
0
|
|
|
|
|
$cheapest_station = $_ if(!$cheapest_station); |
116
|
0
|
0
|
|
|
|
|
if($self->is_less( $_->{$type . "_price"}, |
117
|
|
|
|
|
|
|
$cheapest_station->{$type . "_price"})) |
118
|
|
|
|
|
|
|
{ |
119
|
|
|
|
|
|
|
#print "Replacing " . $cheapest_station->{$type . "_price"} . " with " . $_->{$type . "_price"} . "\n"; |
120
|
0
|
|
|
|
|
|
$cheapest_station = $_; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
#print $_->{$type . "_price"} . "\n"; |
123
|
0
|
|
|
|
|
|
$lowest_price = $cheapest_station->{$type . "_price"}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return $cheapest_station; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub get_most_expensive_station |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
132
|
0
|
|
|
|
|
|
my $type = shift; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my @units = @{$self->{units}}; |
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $highest_price = undef; |
137
|
0
|
|
|
|
|
|
my $most_expensive_station = undef; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
foreach(@units) |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
0
|
|
|
|
|
$most_expensive_station = $_ if(!$most_expensive_station); |
143
|
0
|
0
|
|
|
|
|
if($self->is_greater($_->{$type . "_price"}, |
144
|
|
|
|
|
|
|
$most_expensive_station->{$type . "_price"})) |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
|
|
|
$most_expensive_station = $_; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$highest_price = $most_expensive_station->{$type . "_price"}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $most_expensive_station; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub is_greater |
157
|
|
|
|
|
|
|
{ |
158
|
0
|
|
|
0
|
1
|
|
my ($self, $first, $second) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
$first = $1 if($first =~ /\$(.*)/); |
161
|
0
|
0
|
|
|
|
|
$second = $1 if($second =~ /\$(.*)/); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#print "Comparing $first with $second\n"; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
return 0 if($first =~ /N\/A/); |
166
|
0
|
0
|
|
|
|
|
return 0 if($first =~/nbsp/); |
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
return 1 if($second =~ /N\/A/); |
169
|
0
|
0
|
|
|
|
|
return 1 if($second =~/nbsp/); |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
return 1 if($first > $second); |
172
|
0
|
|
|
|
|
|
return 0; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub is_less |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
|
|
0
|
1
|
|
my ($self, $first, $second) = @_; |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
$first = $1 if($first =~ /\$(.*)/); |
180
|
0
|
0
|
|
|
|
|
$second = $1 if($second =~ /\$(.*)/); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#print "Comparing $first with $second\n"; |
183
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
return 0 if($first =~ /N\/A/); |
185
|
0
|
0
|
|
|
|
|
return 0 if($first =~/nbsp/); |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
return 1 if($second =~ /N\/A/); |
188
|
0
|
0
|
|
|
|
|
return 1 if($second =~/nbsp/); |
189
|
|
|
|
|
|
|
|
190
|
0
|
0
|
|
|
|
|
return 1 if($first < $second); |
191
|
0
|
|
|
|
|
|
return 0; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
195
|
|
|
|
|
|
|
__END__ |