Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > non-numeric indices

Reply
Thread Tools

non-numeric indices

 
 
muralidharck@gmail.com
Guest
Posts: n/a
 
      06-23-2005
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

 
Reply With Quote
 
 
 
 
Greg Bacon
Guest
Posts: n/a
 
      06-23-2005
In article < .com>,
<> wrote:

: 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
--
California is still the best place to start a small business. But you
have to start with a big business.
-- Sen. Tom McClintock, R-Simi Valley
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      06-23-2005
wrote:

> 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
 
Reply With Quote
 
Rossz
Guest
Posts: n/a
 
      06-23-2005
wrote:
> 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.

--
Rossz
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort indices Marc Schellens C++ 3 08-11-2004 03:10 PM
using a string as array indices Justin Perl 1 06-02-2004 11:38 PM
how to efficiently do sorting and get array of indices? b83503104 C Programming 3 05-21-2004 10:44 AM
negative indices for sequence types dan Python 13 09-17-2003 08:43 AM
Problem: Generating random indices for a container Ross MacGregor C++ 5 08-25-2003 06:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57