#!/usr/bin/perl
# # Load modules use CGI::Carp qw(fatalsToBrowser); use LWP::Simple; use integer;
# # Read Input &ReadInput(*cInput);
# set results $cResult = '';
$cBanxicoPage = get("http://www.banxico.com.mx/anuncios_indicadores/indicadores.jsp");
# change the page into plain text
($cPlainPage = $cBanxicoPage) =~ s/<[^>]*>//gs;
# apply some filters
$cPlainPage =~ s/(\w) (\w)/$1_$2/g;
$cPlainPage =~ s/\s//g;
$cPlainPage =~ s/\(/:\(/g;
@cIndicadores = split("•",$cPlainPage);
# extract results and store in the result string
for ($i=1;$i<=$#cIndicadores;$i++)
{ $cResult .= ("BANXICO:" . $cIndicadores[$i] . "\n"); }# store results
open (FILE,"> ../../../tmp/indicadores.txt") || die ("ERROR: no se puede abrir indicadores para escribir\n");
print FILE $cResult;
close (FILE) || die ("ERROR: no pude cerrar indicadores");
# ----- subrutinas
sub ReadInput
# Author: Alejandro Ceballos
# Based on: Perl Routines to Manipulate CGI input [EMAIL PROTECTED]
# Purpose: Make a hash containing all the parameters sent by a form
# Input: Pointer to the hash
# Output: Hash
# Use xmp: &ReadInput(*cInput); print $cInput{thisfield};
{
# Capture variable pointer
local (*cFormatedData) = @_ if @_;
# Create local variables
local ($cRawData,@cData,$nParam,$cKey,$cValue);
# Get raw data
if ($ENV{'REQUEST_METHOD'} eq "GET")
{ $cRawData = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST") # or just 'else'?
{ read(STDIN,$cRawData,$ENV{'CONTENT_LENGTH'});}
# Split data
@cData = split(/[&;]/,$cRawData);
foreach $nParam (0 .. $#cData)
{
# Re-convert spaces
$cData[$nParam] =~ s/\+/ /g;
# Separate key and value to later re-convert special chars
($cKey, $cValue) = split(/=/,$cData[$nParam],2);
$cKey =~ s/%(..)/pack("c",hex($1))/ge;
$cValue =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value in a new array
$cFormatedData{$cKey} .= "\0" if (defined($cFormatedData{$cKey}));
$cFormatedData{$cKey} .= $cValue;
}
return scalar(@cFormatedData);
}--
saludos,
J. Alejandro Ceballos Z. |
---------------------------+---------------------------
http://alejandro.ceballos.info |
[EMAIL PROTECTED] | "A menudo la raz�n comete errores
-------------------------------+ pero nunca lo hace a conciencia."
|
| -- Josh Billings
Bob Showalter wrote: > LWP doesn't do any caching, AFAIK. I think something else is going on. Can > you post your code? >
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
