Hi,
I have a Hashmap called %prevDelivered() and it has key as pty_id and other infomation.
I wnat to read the above hasmap key as well as information into new hashmap called %lastDelivered().
I tried it with the follwoing code. but i am not able to move achive the required functionality.
Please suggest alternative code -
foreach (keys(%prevDelivered)) {
-
my $ptyid = $_;
-
my ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id,
-
$crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file)
-
= @{ $prevDelivered{$ptyid} };
-
$lastDelivered{$ptyid} = ($store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2,
-
$crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file);
-
}
-
9 2275
Hi,
I have a Hashmap called %prevDelivered() and it has key as pty_id and other infomation.
I wnat to read the above hasmap key as well as information into new hashmap called %lastDelivered().
I tried it with the follwoing code. but i am not able to move achive the required functionality.
Please suggest alternative code - foreach (keys(%prevDelivered)) {
-
my $ptyid = $_;
-
my ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id,
-
$crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file)
-
= @{ $prevDelivered{$ptyid} };
-
$lastDelivered{$ptyid} = ($store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2,
-
$crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file);
-
}
- $lastDelivered{$ptyid} = ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5, $crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file);
This is the problematic line. You are trying to assign a list to a hash's value, which can only take a scalar. Before, you treated that hash's value as a reference to an array, so I assume you want to do the same thing here. Then instead of parentheses (), use square brackets []: - $lastDelivered{$ptyid} = [$store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5, $crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file];
- $lastDelivered{$ptyid} = ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5, $crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file);
This is the problematic line. You are trying to assign a list to a hash's value, which can only take a scalar. Before, you treated that hash's value as a reference to an array, so I assume you want to do the same thing here. Then instead of parentheses (), use square brackets []: - $lastDelivered{$ptyid} = [$store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5, $crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file];
Thanks a lot i got the required result now with above code.
I have 2 category ids as 34 and 35 and it have around 100 and 200 records on those ids.
When i repeat the below loop. i am getting final result on %lastDelivered hashmap as 200 records. But i am expecting total 300 records.
How can i hold the data on %lastDelivered hashmap for each iteration? -
foreach ( @keys ) { //* Cat id 34 and 35 *//
-
-
my $category = $_;
-
-
GetLastStoreDelivered( $dbh, $delivery_id,$category, \%prevDelivered );
-
//** Pull forst 100 records for the id 34 and move the data into %lastdelivered() *//
-
-
foreach (keys(%prevDelivered)) {
-
-
my $ptyid = $_;
-
-
my ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id,
-
$crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file) =
-
@{ $prevDelivered{$ptyid} };
-
-
$lastDelivered{$ptyid} = [$store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $
-
crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file];
-
-
}
-
-
}
-
Is $ptyid always a unique value? If not any duplicates will be lost. If it is always a unique value there is no way to tell by looking at the code you posted why you get 200 records instead of the expected 300.
Edit:
Never mind. $ptyid is the keys of the hash %prevDelivered so they must be unique at that point in the script. Maybe the problem is before the loop you posted.
Is $ptyid always a unique value? If not any duplicates will be lost. If it is always a unique value there is no way to tell by looking at the code you posted why you get 200 records instead of the expected 300.
Edit:
Never mind. $ptyid is the keys of the hash %prevDelivered so they must be unique at that point in the script. Maybe the problem is before the loop you posted.
No, I am repeating the loop twice as per category ids 34 and 35. Fisrt id 34 will execute in loop and move 100 records into %lastDelivered() hashmap.
In next run id 35 will execute and overwrite 200 records on %lastDelivered() hashmap. which means i am loosing first 100 records and i am having last run data alone.
My question is here how can we hold previous run data on Hasnmap?
Its very difficult to say because I can't run any code, don't know what the data is, and don't know what your script is doing. But here is a hopefully educated guess, use an array of arrays instead of a hash key that stoes only one array per id:
change this line: -
$lastDelivered{$ptyid} = [$store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $
-
crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file];
-
change to: -
push @{$lastDelivered{$ptyid}}, [$store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $
-
crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file];
-
that means you will also have to change how you parse/access the data stored in $lastDelivered{$ptyid}. You will have to loop through it to get all the arrays, something like: - foreach my $array ( @{$lastDelivered{$ptyid}} ) {
-
print "@{$array}\n";
-
}
You might be able to simplify the foreach loop to this: -
foreach (keys(%prevDelivered)) {
-
push @{$lastDelivered{$ptyid}}, $prevDelivered{$ptyid};
-
-
}
-
then dereference $prevDelivered{$ptyid} array later when you loop through %lastDelivered.
Thanks a lot i got the required result now with above code.
I have 2 category ids as 34 and 35 and it have around 100 and 200 records on those ids.
When i repeat the below loop. i am getting final result on %lastDelivered hashmap as 200 records. But i am expecting total 300 records.
How can i hold the data on %lastDelivered hashmap for each iteration? -
foreach ( @keys ) { //* Cat id 34 and 35 *//
-
-
my $category = $_;
-
-
GetLastStoreDelivered( $dbh, $delivery_id,$category, \%prevDelivered );
-
//** Pull forst 100 records for the id 34 and move the data into %lastdelivered() *//
-
-
foreach (keys(%prevDelivered)) {
-
-
my $ptyid = $_;
-
-
my ($store_id, $pty_id, $trans_cd, $curr_status, $tdlinx_cd, $cat_id,
-
$crc_mod1, $crc_mod2, $crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8, $inc_in_file) =
-
@{ $prevDelivered{$ptyid} };
-
-
$lastDelivered{$ptyid} = [$store_id, $pty_id, $trans_cd, $curr_status,
-
$tdlinx_cd, $cat_id, $crc_mod1, $crc_mod2, $
-
crc_mod3, $crc_mod4, $crc_mod5,
-
$crc_mod6, $crc_mod7, $crc_mod8,
-
$inc_in_file];
-
-
}
-
-
}
-
Ruhee070806,
Ok, this is twice now that I have corrected your not using code tags. Please read this sites Posting Guidelines and use the proper code tags from now on. They are not optional.
Regards,
Jeff
(Moderator)
Ruhee070806,
Ok, this is twice now that I have corrected your not using code tags. Please read this sites Posting Guidelines and use the proper code tags from now on. They are not optional.
Regards,
Jeff
(Moderator)
Thanks a lot and now i am able to hold the data into new Hashmap for each iteration.
I got struck into one more problem. I have around 1.5 million data needs to pul from database using Perl module and put those data into Hashmap. -
-
sub GetLastStoreDelivered
-
{
-
my $sql = <<EOS;
-
SELECT store_id
-
, party_id
-
, curr_status
-
, cat_id
-
, mod1
-
, mod2
-
, mod3
-
, mod4
-
, mod5
-
, mod6
-
, mod7
-
, mod8
-
FROM client
-
WHERE end_dt = '31-DEC-2500'
-
EOS
-
-
my $sth = $dbh->prepare( $sql );
-
if ( !$sth ) {
-
LogMsg( "Error preparing SQL:\n$sql" . DBI->errstr );
-
die "Could not prepare statement: " . DBI->errstr;
-
}
-
-
if ( !$sth->execute() ) {
-
LogMsg( "Error executing SQL:\n$sql" . DBI->errstr );
-
die "Could not execute: " . DBI->errstr;
-
}
-
-
while ( my @row = $sth->fetchrow_array() ) {
-
my $pty_id = $row[1];
-
$$delivered{$pty_id} = [ @row ];
-
}
-
-
$sth->finish;
-
return $delivered;
-
}
-
-
I am getting out-of-memory error here.....
And data will increase on Client table every month.
Can you please let me know how to overcome on this. Is we need to add more cpus to my system or is any other solution which exits.
You need more memory. Or you need to free up memory. Memory as in system memory, RAM.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve Johnson |
last post by:
Been banging my head on this for two days now. Hope someone can help!
My test program below is in the form of a single JSP, with a Node class
build in. (All the coded needed to run is below.)
...
|
by: Marilyn Hart |
last post by:
Hi
I hope there is someone out there that may be able to help me.
I have a Hashmap called that contains Bank Account objects,
it is made up as follows.
Bank Acc Number - int
Bank Acc Type...
|
by: Myster Ious |
last post by:
Polymorphism replaces switch statements, making the code more
compact/readable/maintainable/OO whatever, fine!
What I understand, that needs to be done at the programming level, is
this:
a...
|
by: Pino |
last post by:
Hi, to everybody,
let's consider this scenario: you have 1 data-table and 10
dictionary-tables; the data-table has 5 million records and 30 columns, 10
of these columns have a foreign-key to the...
|
by: Lee |
last post by:
Hi,
are there equivalents in c# as java vectors and hashmaps?
thanks
lee
|
by: shiniskumar |
last post by:
Ive got a collection that is populated by some key/value pairs.
How can i iterate ie to get its each key/value pair?
|
by: milanjain |
last post by:
Merge two HashMaps into one in asceding order
|
by: namrata mukherjee |
last post by:
i have a Hashmap whose value is an array list which in turn is a Hashmap.please tell me how to implement this in code
|
by: Peter Morris |
last post by:
I wasn't expecting this...
(Time in MS)
Linq 858
Sort 9721
Dict 316
Linq - Sort = -8863
Linq - Dict = 542
I was originally writing something like the dictionary one but then I
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |