passing hash of arrays by reference

J

Jerry Preston

Hi!

I am lost in trying to deal an hash of arrays.

First I go out and collect a group of number and pass back:

$RESULTS = $DAT->read_data( ""9994658", $DEBUG );

This works great and I can print the contents:

print " @{ $RESULTS->{ names }->{ 'Jerry' }";

Now I want to pass this to a sub to print out a graph using GD;

&graph_data( $j, $x_label_o, $y_label_o, @{ $RESULTS->{ names }->{
'Jerry' }} );

sub graph_data {

my ( $date_type, $x_label, $y_label, @data ) = @_;

Then:

my $mygraph = GD::Graph::linespoints->new( 600, 400 );

I get the error:

Invalid data set: 0

at

$myimage = $mygraph->plot( \@data ) or die $mygraph->error;

I know that I am not passing the reference/deference correctly.

What am I missing?

Thanks,

Jerry
 
B

Ben Morrow

Quoth "Jerry Preston said:
First I go out and collect a group of number and pass back:

$RESULTS = $DAT->read_data( ""9994658", $DEBUG );

This works great and I can print the contents:

print " @{ $RESULTS->{ names }->{ 'Jerry' }";

No you can't. Please post actual code.
Now I want to pass this to a sub to print out a graph using GD;

&graph_data( $j, $x_label_o, $y_label_o, @{ $RESULTS->{ names }->{
'Jerry' }} );

Don't call subs with & unless you know why you are doing it.
sub graph_data {

my ( $date_type, $x_label, $y_label, @data ) = @_;

use Data::Dumper;
warn Dumper \@data;

or IMHO easier to understand and use, install Data::Dump and then

use Data::Dump qw/dump/;
warn dump \@data;

Check this is what you think it should be.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top