#!/usr/bin/perl -w
use strict;
use HTML::TreeBuilder;

sub processgtpage
{
	my $content= shift;

	my $tree = HTML::TreeBuilder->new;
	$tree->parse($content);

#our $saldo= amountToValue($tree->address("0.1.2.0.0.1.1")->content()->[0]);
	my $table= htmlTableToArray($tree->address("0.1.2.1"));
	$tree = $tree->delete();

	return $table;
}


sub amountToValue {
	my $strval= shift;

	$strval =~ s/\.//g;
	$strval =~ s/,/\./g;

	return $strval;
}

sub htmlTableToArray {
	my $table= shift;
	my @result= ();


	my $content= $table->content();

	push(@result, htmlTableRowToArray($content->[0]));

	for (my $i=1 ; $i<$#$content; $i += 2) {
		push(@result, htmlTableRowToArray($content->[$i]));
	}
	return \@result;
}

sub htmlTableRowToArray {
	my $row= shift;
	my @result= ();

	my $content= $row->content();

	for (my $i=0 ; $i < $#$content; $i++) {
		push(@result, htmlElementValue($content->[$i]));
	}

	return \@result;
}

sub htmlElementValue {
	my $element= shift;

	my $result= "";
	my $content= $element->content();

	for (my $i= 0 ; $i <= $#$content ; $i++) {
		if (ref(\$content->[$i]) eq 'SCALAR') {
			$result .= $content->[$i];
		} else {
			$result .= " ";
		}
	}
	return $result;
}

1;

