Perl style array in C?

R

Robert Oschler

I know this is a Perl newsgroup and not a "C" newsgroup, but I am hoping
that there's at least a few of you out there also program in "C".

I am converting a Perl script over to "C" for a potential open source
project. I need some open source "C" code that will give me the same
functionality of a Perl Style associative array:

someArray["a_key_label"] = 6;

I know I can't get the same syntactic sugar as Perl offers, with the usage
of a string as the array key surrounded by square brackets. I just want the
general functionality, that's all.

Do any of you Perl programmers that also know "C", know of any open source
"C" code that provides a container with the same behavior as Perl style
arrays? URL's if you got 'em please.

Thanks.
 
A

A. Sinan Unur

someArray["a_key_label"] = 6;
....

You'll probably have better luck searching for "hash table" rather than
"array".
Do any of you Perl programmers that also know "C", know of any open
source "C" code that provides a container with the same behavior as
Perl style arrays? URL's if you got 'em please.

Why are we supposed to search Google for you?

Why not go to comp.lang.c, and ask for recommendations for a C hash table
library?

Sinan.
 
A

A. Sinan Unur

A. Sinan Unur said:
someArray["a_key_label"] = 6;
...

You'll probably have better luck searching for "hash table" rather
than "array".

associative array.

I had in mind something I had read once, and apparently only partially
remembered:

Nomenclature

Dictionaries, as explained earlier, are unordered collections of values
indexed by unique keys. They are sometimes called associative arrays or
maps. They can be implemented in several ways, one of which is by using
a data structure known as a hash table (and this is what Perl refers to
as a hash).

Perl's use of the term "hash" is the source of some potential confusion,
because the output of a hashing function is also sometimes called a hash
(especially in cryptographic contexts), and because hash tables aren't
usually called hashes anywhere else.

To be on the safe side, refer to the data structure as a hash table, and
use the term "hash" only in obvious, Perl-specific contexts.

See http://www.perl.com/lpt/a/2002/10/01/hashes.html
 
J

John Bokma

A. Sinan Unur said:
Perl's use of the term "hash" is the source of some potential confusion,

Yup, people think I smoke a lot of weed when I talk about how I program :-
D.
 
J

Joe Smith

Robert said:
I need some open source "C" code that will give me the same
functionality of a Perl Style associative array:

someArray["a_key_label"] = 6;

I know I can't get the same syntactic sugar as Perl offers, with the usage
of a string as the array key surrounded by square brackets.

I hope you are aware that perl does not use square brackets for
associative arrays. Hashes use curly braces.
Perl evaluates
$someArray["a_key_label"] = 6;
as
$someArray[0] = 6;
since "a_key_label" is non-numeric.

-Joe
 

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
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top