in reply to Re: Using grep to remove array element from HoAoH leaving empty array-hash element
in thread Using grep to remove array element from HoAoH leaving empty array-hash element
The code I'm using to initialize the whole structure is:
my $bros= {'1958' => [], '1959' => [], '1960' => [], '1961' => [], '1962' => [], '1963' => [], '1964' => []};
since I was lazy and wanted to pre-build my data structure.
Here's the Data::Dumper listing of before and after the grep:
before grep: $VAR1 = \[ { 'state' => 'OR', 'last' => 'Bertelson', 'first' => 'Gordon', }, { 'state' => '', 'last' => 'Blaise', 'first' => 'Larry', }, { 'state' => 'OR', 'last' => 'Douda', 'first' => 'Henry B.', }, { 'state' => 'NSW 221', ' => 'Australia', 'last' => 'McHolick', 'first' => 'Dwane', }, { 'state' => 'OR', 'last' => 'Murray', 'first' => 'Melvin', }, { 'state' => 'OR', 'last' => 'Perry', 'first' => 'Larry', }, { 'state' => '', 'last' => 'Peterson', 'first' => 'Ken', }, { 'state' => 'OR', 'last' => 'Rianda', 'first' => 'Dave', }, { 'state' => 'OR', 'last' => 'Steffanoff', 'first' => 'Nick', }, { 'state' => 'CA', 'last' => 'Turner', 'first' => 'Paul', }, { 'state' => 'OR', 'last' => 'Wilson', 'first' => 'Dick', }, {} ]; after grep: $VAR1 = \[ { 'state' => 'OR', 'last' => 'Bertelson', 'first' => 'Gordon', }, { 'state' => '', 'last' => 'Blaise', 'first' => 'Larry', }, { 'state' => 'OR', 'last' => 'Douda', 'first' => 'Henry B.', }, { 'state' => 'NSW 221', 'last' => 'McHolick', 'first' => 'Dwane', }, { 'state' => 'OR', 'last' => 'Murray', 'first' => 'Melvin', }, { 'state' => 'OR', 'last' => 'Perry', 'first' => 'Larry', }, { 'state' => '', 'last' => 'Peterson', 'first' => 'Ken', }, { 'state' => 'OR', 'last' => 'Rianda', 'first' => 'Dave', }, { 'state' => 'OR', 'last' => 'Steffanoff', 'first' => 'Nick', }, { 'state' => 'OR', 'last' => 'Wilson', 'first' => 'Dick', }, {} <- here's the empty hash ];
so you can see exactly what I'm saying by there's an empty hash where Paul Turner's information was.
As far as removing the element, I thought using the negative grep would find everything that didn't match what I wanted and put it in the array. I thought I was on the right track with the negative grep but I don't understand the empty hash in the array still being there.
My assumption is that grep is choking for whatever reason on that empty hash, so is a negative grep the way to go here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using grep to remove array element from HoAoH leaving empty array-hash element
by Aristotle (Chancellor) on Aug 11, 2004 at 05:12 UTC | |
by Popcorn Dave (Abbot) on Aug 11, 2004 at 19:51 UTC | |
by Aristotle (Chancellor) on Aug 11, 2004 at 22:31 UTC |