non-numeric indices

M

muralidharck

Hi all,

Can anyone tell me or point to a reference to know more about using
non-numeric indices for arrays?

If so, how can I use it for my applications?

Typical scenario would be database records, where I want my index to be
based off Last name . and would like to access the array as

$Record[$LastName][$Salary] = $1000;

This way I dont need to parse the entire list (myself) to find the
matching last name and then assign that record the salary value.

Thanks,
Murali
 
G

Greg Bacon

: Can anyone tell me or point to a reference to know more about using
: non-numeric indices for arrays?
:
: If so, how can I use it for my applications?

Read about hashes in the perldata manpage.

$Record{$lastname}{salary} = 1234;

Hope this helps,
Greg
 
A

A. Sinan Unur

Can anyone tell me or point to a reference to know more about using
non-numeric indices for arrays?

Perl's arrays require numeric indices, so, it seems like you are out of
luck.
If so, how can I use it for my applications?

Depends on your application.
Typical scenario would be database records, where I want my index to be
based off Last name . and would like to access the array as

$Record[$LastName][$Salary] = $1000;

Well, that is not going to work. First, $1000 is likely to contain a
meaningless value as you probably did not have a regex match with at
least 1000 captures prior to this line. Second, $LastName and $Salary
are likely not integers.

On the other hand, in Perl, you could use a hash:

my %records;

$records{$last_name}{$salary} = '$10000';

But that's silly as well: I mean, what would $salary contain? Hmmm ...
How about:

$records{$last_name}{salary} = '$10000';

Please do visit

<URL:http://learn.perl.org/>

and read the posting guidelines for this group.
This way I dont need to parse the entire list (myself) to find the
matching last name and then assign that record the salary value.

This makes absolutely zero sense. What does any of this have to do with
parsing?

Sinan
 
R

Rossz

Hi all,

Can anyone tell me or point to a reference to know more about using
non-numeric indices for arrays?

If so, how can I use it for my applications?

Typical scenario would be database records, where I want my index to be
based off Last name . and would like to access the array as

$Record[$LastName][$Salary] = $1000;

You would use hashes for this. They also nicely work with the DBI
module's tools for selecting into a hash.
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top