vsurend has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks, I am getting some values from database by querying. This data contains, 4 fields namely, Application Name, Date, Location, Average Response Time. This four fields will have multiple records.

Sample Data :

Application Name -Date -Location -AverageResponseTime

SMS3 -01/01/2012 -San Jose -2.24

SMS3 -01/02/2012 -San Jose -2.31

SMS3 -01/03/2012 -San Jose -2.43

SMS3 -01/01/2012 -New York -2.25

SMS3 -01/02/2012 -New York -2.13

SMS3 -01/03/2012 -New York -2.91

In iterations till the records are over I am getting one row of data into and array.

 while ( my @row = $sth->fetchrow_array( )

I want to get this array into hash map and then convert the fields like, Date, San Jose,New York ,... and its corresponding average response times as other rows

Data should become in format like :

Date -San Jose -New York

01/01/2012 -2.24 -2.25

01/02/2012 -2.31 -2.13

01/03/2012 -2.43 -2.91

Can you please help me to use hashmap for this

Thanks, Vidya Surendran

Replies are listed 'Best First'.
Re: Hash map in perl/tk
by zentara (Cardinal) on Jan 24, 2012 at 11:09 UTC
    What is a hash map? From your title, I gather you want to dump your table into a Tk widget. There are many types of widgets. Look at this:
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Table; my $mw= tkinit; $mw->geometry("400x400+100+100"); my $table = $mw->Scrolled('Table', -rows => 20, -columns => 50, -scrollbars => 'osoe', -takefocus => 1)->pack; my %widgets; for my $row(1..20){ for my $col(1..50){ $widgets{$row}{$col} = $table->Button( -text=> "$row - $col", -background => 'white' ); $table->put( $row,$col,$widgets{$row}{$col} ); } } MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Hash map in perl/tk
by Marshall (Canon) on Jan 25, 2012 at 00:27 UTC
    I also don't know what a "hash map" is?

    It looks to me like there is an SQL question that isn't being asked. Basically if you use the DB to correlate the stuff that belongs to one date into a single row (01/01/2012 -2.24 -2.25), then the job of sticking this data into the display becomes easier.

    As it is now, its looks like you will have to write Perl code to correlate this one line per city stuff into a "spreadsheet like" format. You didn't show any of the SQL code. But the closer the results returned from SQL are to what you want to be displayed on the row, the less Perl code there will be (i.e. if @row winds up actually being a "row" in the display instead of column in the display, then I think the transformation to the display is easier). But I don't know how to help with this absent the SQL query stuff.

    As an example, if the SQL could return something like below, then creating the display should be easier? I am certainly not an SQL guru, but other Monks are.

    my @rows = [("01/01/2012","San Jose",2.24,"New York",2.25), ("01/02/2012","San Jose",2.31,"New York",2.13), ("01/20/2012","San Jose",undef,"New York",3.12) ];