non-numeric indices

Discussion in 'Perl Misc' started by muralidharck@gmail.com, Jun 23, 2005.

  1. Guest

    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
     
    , Jun 23, 2005
    #1
    1. Advertising

  2. Greg Bacon Guest

    In article <>,
    <> 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
     
    Greg Bacon, Jun 23, 2005
    #2
    1. Advertising

  3. 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
     
    A. Sinan Unur, Jun 23, 2005
    #3
  4. Rossz Guest

    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
     
    Rossz, Jun 23, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    393
  2. Replies:
    5
    Views:
    981
    X-Centric
    Jun 30, 2005
  3. darrel
    Replies:
    4
    Views:
    868
    darrel
    Jul 19, 2007
  4. jobs

    int to numeric numeric(18,2) ?

    jobs, Jul 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,017
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 22, 2007
  5. Patrick Doyle

    indices of non nil elements in an array

    Patrick Doyle, Aug 25, 2008, in forum: Ruby
    Replies:
    8
    Views:
    129
    Patrick Doyle
    Aug 25, 2008
Loading...

Share This Page