A
Artemis Fowl
Hello Experts,
I am dealing with an array of hashes in my program. I need to pick
every hash in the array, check a few keys and depending on it's value,
I need to either retain this hash or delete this hash from the array.
Please allow me to explain with a piece of sample code.
#!/usr/bin/perl -w
use strict;
my %MonthHash = ( "Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4,
"Jun", 5, "Jul", 6, "Aug", 7, "Sep", 8, "Oct", 9, "Nov", 10, "Dec",
11, "Delete", "True");
my %WeekHash = ("Mon", 0, "Tue", 1, "Wed", 2, "Thu", 4, "Fri", 5,
"Sat", 6, "Sun", 7, "Delete", "False");
my %AgeHash = ("John", 21, "Susan", 23, "Gary", 18, "Christy", 20,
"Delete", "True");
my @arrayOfAll;
push(@arrayOfAll, %MonthHash);
push(@arrayOfAll, %WeekHash);
push(@arrayOfAll, %AgeHash);
I need to parse arrayOfAll, picking up each Hash turn by turn, and in
each of the Hashes, I want to check the value of the key "Delete". If
it is "True", then I want to delete the entire hash from the array.
Is there any way I could achieve this?
From what I see when I debug the script is that in arrayOfAll, the
details of different hashes are lost and all the key value pairs are
stored as just elements of the array.
Am I doing something wrong?
Any help will be greatly appreciated.
P.S : For the example, I have considered different Hashes. In the real
program, all the hashes have the same structure. Just thought this
information might help.
Thanks in advance,
Artemis.
I am dealing with an array of hashes in my program. I need to pick
every hash in the array, check a few keys and depending on it's value,
I need to either retain this hash or delete this hash from the array.
Please allow me to explain with a piece of sample code.
#!/usr/bin/perl -w
use strict;
my %MonthHash = ( "Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4,
"Jun", 5, "Jul", 6, "Aug", 7, "Sep", 8, "Oct", 9, "Nov", 10, "Dec",
11, "Delete", "True");
my %WeekHash = ("Mon", 0, "Tue", 1, "Wed", 2, "Thu", 4, "Fri", 5,
"Sat", 6, "Sun", 7, "Delete", "False");
my %AgeHash = ("John", 21, "Susan", 23, "Gary", 18, "Christy", 20,
"Delete", "True");
my @arrayOfAll;
push(@arrayOfAll, %MonthHash);
push(@arrayOfAll, %WeekHash);
push(@arrayOfAll, %AgeHash);
I need to parse arrayOfAll, picking up each Hash turn by turn, and in
each of the Hashes, I want to check the value of the key "Delete". If
it is "True", then I want to delete the entire hash from the array.
Is there any way I could achieve this?
From what I see when I debug the script is that in arrayOfAll, the
details of different hashes are lost and all the key value pairs are
stored as just elements of the array.
Am I doing something wrong?
Any help will be greatly appreciated.
P.S : For the example, I have considered different Hashes. In the real
program, all the hashes have the same structure. Just thought this
information might help.
Thanks in advance,
Artemis.