    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::ParseExcel;
	use switch;
	
    my $filename = $ARGV[0];
    my $parser   = Spreadsheet::ParseExcel->new();
    my $workbook = $parser->Parse($filename);
    my $worksheet = $workbook->worksheet('Periodic'); 
    my $characters_before_country = "15";
    my $country = substr $filename, $characters_before_country, (index($filename, '.') - $characters_before_country);    

    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();
    my $column = 3;
	my @economical = ( "Rental revenue", "Handling revenue", "Freight revenue", "Other sales revenue", "Rental margin",
						"Handling margin 1", "EBIT");
	my $readState = "";
	
	# Haetaan Warehouse solujen sijainti ja talletetaan taulukkoon.
	sub haeVarastot {
		my @warehouse = [];
		my $i = 0;
		for my $row ( $row_min .. $row_max ) {
			my $cell = $worksheet->get_cell( $row, 0 );
			if (defined $worksheet->{Cells}[$row][0]) {
				if ($worksheet->{Cells}[$row][0]->Value eq "Warehouse:")
				{
					print "Warehouse founded on row: " . $row . " column: 0\n";
					print "Warehouse name: " . $worksheet->{Cells}[$row][1]->Value . "\n";
					$warehouse[$i] = $row;
					$i++;
				}
			}
		}
		return @warehouse;
	}
	
	# Haetaan yhden kuukauden tiedot
	sub haeKuukausi {
		
	}
	
	sub yhdistaKentat {
		for my $row ( $row_min .. $row_max ) {
			my $cell = $worksheet->get_cell( $row, 0 );
			if (defined $cell) {
				
				if ($cell->unformatted() eq "Economical")
				{
					$readState = "economical";
				}
				elsif ($cell->unformatted() eq "Operational")
				{
					$readState ="";
				}
				elsif ($cell->unformatted() eq "Quality")
				{
					$readState ="quality";
				}
			}
			
			my $temp = $worksheet->get_cell($row + 1, 1);
			
			switch ($readState) {
				
				#case "economical"	{ print "Economical-". $temp->Value . "\n" }
				#case "quality"		{ print "Quality-". $temp->Value . "\n" }
				#else				{ print "" }
			}
			#if ($temp && $readState eq "economical") {	
					
			#	print "Economical-". $temp->Value . "\n";
			#	}
			}	
		}
	
	
    # tähän do while columnien mukaan. mennään rivejä läpi kunnes päästään viimeiseen
	#my @warehouses = haeVarastot();
	yhdistaKentat();