The Right Tool for The Right Job (was Re: Grouping perl foreach values)

Alex Satrapa grail at
Wed Jul 10 00:49:00 EST 2002

On Tuesday, July 9, 2002, at 05:28 , Michael Still wrote:

> I think this sums it up. I wasn't too interested in finding the spare
> brain capacity to complicate things this was. The data is a triple of
> (return type, function name, arguement list).
> Is there are trivial was of implementing a structure which has these 
> three
> elements?

%item1 = ('type' => "int", 'name' => "foo", 'args' => ["blah", "blag", 
%item2 = ('type' => "char", 'name' => "bar", 'args' => ["floogle"]);

@items = (\%item1, \%item2);


%item1 = ('type' => "int", 'args' => ["blah", "blag", "blurgle"]);
%item2 = ('type' => "char", 'args' => ["floogle"]);

%items = ('foo' => \%item1, 'bar' => \%item2);

OR EVEN (this data structure is not the same implementation)

$items = {};

$items->{'foo'}->{'type'} = "int";
$items->{'foo'}->{'args'} = ["blah", "blag", "blurgle"];

$items->{'bar'}->{'type'} = "char";
$items->{'bar'}->{'args'} = "floogle";

Of course, if your arguments list needs types, you get even more 
expressive with things like
$item =
         'type' => "int",
         'name' => "foo",
         'args' => {
             "blah" => "int",
             "blag" => "void *",
             "blurgle" => "char **"

To me, this is a simple data structure - given the complexity of the 
data to be modelled.  To a dyed-in-the-wool C programmer, it's an unholy 
mess of quotes and curly braces in the wrong places.  I cannot think of 
a simpler (more easily understood) data structure that captures the 
semantics of the indicated problem domain.


"Programming is like sex: one mistake and you have to support it for the 
rest of your life." -Michael Sinz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 225 bytes
Desc: not available
Url :

More information about the linux mailing list