Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Array or Hash problem!

by spazm (Monk)
on Mar 04, 2010 at 18:05 UTC ( #826772=note: print w/ replies, xml ) Need Help??


in reply to Array or Hash problem!

I think I understand your request, but I may have misunderstood the mapping of code, number and acc_id.

you have: @code_array ==> full code strings of the accounts.
you have: @code_array_no_letters => numeric version of code strings.
you have: a database keyed on numeric versions of the code strings mapping to an acc_id.
You want: a list of code => acc_id.

My advice is to always start with a picture (literal or figurative) of your data and your final output. This is very helpful when explaining to others and asking for help.

#!/usr/bin/perl use warnings; use strict; my @code_array = qw(7772344 2233421 TMW2222987 TMA2222333 TMW9999988 AMQ8873332 AMQ1111877); #prime a lookup from the numeric code back to the full code. my %code_by_num; for my $code (@code_array) { (my $num = $code) =~ s/\D//g; $code_by_num{ $num } = $code; } #... while (my $pt = $sth->fetchrow_hashref) { my $accountnumber = $pt->{'accounts'}; my $acc_id = $pt->{'id'}; my $accountcode = $code_by_num{ $accountnumber }; print "$accountcode $acc_id\n" }


Comment on Re: Array or Hash problem!
Download Code
Re^2: Array or Hash problem!
by Anonymous Monk on Mar 04, 2010 at 18:49 UTC
    This is one way of doing it, values in @code_array are the accounts in its original format, values in @code_array_noletter are the values from @code_array without the letters at the beginning of the account number since this table is numeric. My objective is, remove the letters from the beginning of the code from the account numbers that of course has letters at the beginning, its done. Second go to this database table find if any of this account numbers are in there and bring the results back which will include the ID, done I can go in there find what I want. Now after I find the match by the number of the account only i need to reattach the code back, like if one of my result will be "2222987" and its ID is "66", at the end I would like to be able to print TMW2222987 (original format) and its ID 66. I hope I made it a little clear this time. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://826772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-07-26 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (177 votes), past polls