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

Thank you all again in advance for your help

I am currently using the Spreadsheet::Read module to pull in data from an excel sheet. I would like to put my data points into a hash table as follows:
use Spreadsheet::Read; my %pointData{D.xls} = ReadData(fileD.xls) my %coordinates = ( x1 => $pointData(D.xls)->[1]->{A1}, y1 => $pointData(D.xls)->[1]->{A2}, z1 => $pointData(D.xls)->[1]->{A3}, );

This is a simplification of my code, but it should be an accurate representation. When I try to run the script and print x1 using print "$coordinates{x1}";, it tells me that $coordinates{x1} is uninitialized. I was wondering if anyone sees something wrong with my code that could be causing this. I am assuming that I am missing an obvious thing, but I have read through a lot of documentation and still cannot figure it out

Many Thanks!

Replies are listed 'Best First'.
Re: Dereferencing within Hash Assignment
by Your Mother (Archbishop) on Sep 24, 2010 at 20:10 UTC

    Your declaration/assignment is wonky too:

    use Spreadsheet::Read; my %pointData{D.xls} = ReadData(fileD.xls)

    Should be more like-

    use warnings; use strict; use Spreadsheet::Read; my %pointData; $pointData{"D.xls"} = ReadData("fileD.xls"); # Updated, added quotes.
      It should be and is in my program. I was attempting to be concise to save people the reading time (clearly a mistake on my part). But the declarations in my program are exactly how you wrote them. As for the #Updated, added quotes., my program is actually using variables in those places. I have printed each variable to ensure that it truly holds "D.xls" and "fileD.xls".
Re: Dereferencing within Hash Assignment
by toolic (Bishop) on Sep 24, 2010 at 19:59 UTC
    According to the documentation for Spreadsheet::Read, the ReadData function returns a reference to an array. Typically, you would assign it to a scalar, as demonstrated in the SYNOPSIS:
    use Spreadsheet::Read; my $ref = ReadData('file.xls');

    See also: perlreftut

      Apologies, I should have mentioned this earlier. I am actually doing this for multiple files. That is why I am putting the array reference into a hash. I made a related post on this here How Best to Handle Data. In the end, I have a hash with every key being a different file name and the value being the array reference from ReadData.

Re: Dereferencing within Hash Assignment
by Anonymous Monk on Sep 24, 2010 at 20:46 UTC
    I imagine that in the assignment to %coordinates, $pointData(D.xls) should be $pointData{D.xls}.