> -----Original Message-----
> From: Elie De Brauwer [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 09, 2001 9:01 AM
> To: Bob Showalter
> Subject: Re: Creating a hash from a name stored in a variable ...
> 
> 
> > > I searched google, asked some people on irc but no-one could
> > > answer me.
> > >
> > > $max_index  is a value gotten from a database which contains
> > > the number of
> > > entry's
> > >
> > > for($i = 0, $i < $max_index, $i++){
> > >          %data$1{name} = #get the name from the database
> > > matching the index
> > > and store
> > > it here ...
> > > }
> > >
> > > This is very simplistic in not working code what i want to
> > > do. I want to
> > > generate a hash variable name. %data1, %data2 .... where the
> > > numbers are read
> > > from a variable .... How can i do this ?
> >
> > Ooh, don't do that. What good will it do you to have a bunch of
> > hashes with names not known at compile time?
> >
> > Instead, have a hash, %data, with keys coming from the
> > variable part:
> >
> >    $data{$i}{name} = "blah";
> >
> > Or an array, @data, indexed by $i:
> >
> >    $data[$i]{name} = "blah";
> 
> You don't want to know why i need it, but because you insist, 

Wait a minute. I never insisted. My "what good will it do" question
was purely rhetorical. Becuase the answer is "no good at all".

You may *think* you need it, but in fact you *don't* need it.

> i'm building a 
> graph, (with Chart::Graph::Gnuplot) subroutine.

OK, fine. You need to pass a hash for each data series.

> This graph 
> display the 
> harddiskusage on a Linux system.  The values on the x axis 
> depend on the 
> number of checkup (every month data is collected and stored 
> in a database). 
> Now i want 1 one graph the results of each partition (each 
> with a seperate 
> curve). To do this i need an array, an array with refs to a 
> hash and one or 
> two array (for each partition) so, i need a way to create an 
> incertain number 
> of hashes and an incertain (but the same) number of arrays. 

That's fine. You can create a variable number of hashes and
arrays. No problem. The problem is trying to create a variable
number of *named* hashes.

What I'm saying is instead of creating:

   %data0 = (name => "foo");
   %data1 = (name => "bar");
   %data2 = (name => "baz");

   build_graph(\%data1, \%data2, \%data3);

Create it like this:

   $data[0] = { name => "foo" };
   $data[1] = { name => "bar" };
   $data[2] = { name => "baz" };

   build_graph(@data);

build_graph will see the *exact* same data. But the latter will be 
*far* easier to construct programmatically than the former.

> 
> So i need a method for creating %data1 %data2 ....

You really don't, trust me...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to