Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Add new rows and data to array.

by Anonymous Monk
on Mar 19, 2020 at 16:23 UTC ( #11114482=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I had a similar question a few days ago, but the test data I had wasn't right, so I am hopping to get another shot here, cause I am stuck.

First, add new rows to the data where "status = Main", I have that on the first "foreach loop", thanks!

Here is where I am stuck, adding new values from "status = Extra" into "status = Main" where ID in "status = Main" is equal the ID in "status = Extra".
So in this case, the end result I am trying to get would be like this,:

$VAR3 = { 'new_City' => 'BO', 'ID' => '2222', 'status' => 'Main', 'name' => 'John D', 'City' => 'NY', 'state' => 'UA', 'new_ad1' => '100 main St.', 'Ad1' => '20 North Central St.', 'new_z_code' => '0007', 'new_name' => 'Tony Star', 'zCode' => '0002' }; $VAR6 = { 'new_City' => 'MA', 'ID' => '1111', 'status' => 'Main', 'name' => 'Charles D', 'City' => 'NM', 'state' => 'CA', 'new_ad1' => '44 Dell St', 'Ad1' => '12th Street', 'new_z_code' => '9857', 'new_name' => 'Marie Doe', 'zCode' => '2334' }; # Noticed that this one didn't have any "status = Extra" associated wi +th it, so the new added rows are empty, its just fine like that. $VAR9 = { 'new_City' => '', 'ID' => '8888', 'status' => 'Main', 'name' => 'AKAKAK', 'City' => 'AA', 'state' => 'PP', 'new_ad1' => '', 'Ad1' => '1AAAA', 'new_z_code' => '', 'new_name' => '', 'zCode' => 'TTTT' }; <br><br>


Here is a sample code to show what I am trying to do:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data =[ { Ad1 => '20 North Central St.', status => 'Main', City => 'NY +', zCode => '0002', name => 'John D', ID => '2222', state => 'TO +' }, { Ad1 => '15 South Street', status => 'Property', City => 'NY +', zCode => '0002', name => 'John V', ID => '2222', state => 'TO +' }, { Ad1 => '100 main St.', status => 'Extra', City => 'BO +', zCode => '0007', name => 'Tony Star', ID => '2222', state => 'UA +' }, { Ad1 => '5540 Chelsea Avenue', status => 'Cabin', City => 'NE +', zCode => '4562', name => 'Carly Simon', ID => '2222', state => 'TO +' }, { Ad1 => '12th Street', status => 'Main', City => 'NM +', zCode => '2334', name => 'Charles D', ID => '1111', state => 'CA' + }, { Ad1 => '44 Dell St', status => 'Extra', City => 'MA +', zCode => '9857', name => 'Marie Doe', ID => '1111', state => 'CA +' }, { Ad1 => '33 Dust Road', status => 'Property', City => 'ET +', zCode => '3345', name => 'Chapim Thor',ID => '1111', state => 'CA' + }, { Ad1 => '01 Charles St', status => 'Cabin', City => 'CA +', zCode => '2334', name => 'Claud Odur', ID => '1111', state => 'CA' + }, { Ad1 => '1AAAA', status => 'Main', City => 'AA', zCode => 'T +TTT', name => 'AKAKAK', ID => '8888', state => 'PP' }, { Ad1 => '2AAAA', status => 'Test', City => 'BB', zCode => 'W +WWW', name => 'BXBXBX', ID => '8888', state => 'HH' }, { Ad1 => 'CCCCC', status => 'Property', City => 'ET', zCode => '3 +345', name => 'Chapim Thor', ID => '8888', state => 'CA' }, { Ad1 => 'DDDDD', status => 'Cabin', City => 'CA', zCode => '2 +334', name => 'Claud Odur', ID => '8888', state => 'CA' }, ]; # Add new rows to data where status equal Main my %new_row; foreach my $get_data (@$data) { if ( $get_data->{ 'status' } eq 'Main' ){ # Add New rows %new_row = ( new_name => '', new_ad1 => '', new_City => '', new_z_code => '' ); @$get_data{keys %new_row} = values %new_row; } } # At this point all arrays with status equal "Main" has all the new ro +ws added with empty values. print Dumper @$data; # Now add new values from Extra into Main where ID in Main is equal ID + in Extra. # Not working, inserts the values into the rows, but over writes the v +alues. # Cant think on how to check for the IDs equality in status=Main and I +D in status=Extra. my %new_row_data; foreach my $getdata (@$data) { if ( $getdata->{ 'status' } eq 'Extra' ){ %new_row_data = ( status => 'Main', new_name => $getdata->{ 'name' }, new_ad1 => $getdata->{ 'Ad1' }, new_City => $getdata->{ 'City' }, new_z_code => $getdata->{ 'zCode' } ); @$getdata{keys %new_row_data} = values %new_row_data; } } print Dumper @$data; exit;

Thanks once again for looking!!

Replies are listed 'Best First'.
Re: Add new rows and data to array.
by hippo (Chancellor) on Mar 19, 2020 at 17:29 UTC

    Perhaps it would help everyone if you could take a moment to explain why you have chosen not to use an RDBMS for this task, seeing as how that would appear to be an optimal solution?

Re: Add new rows and data to array.
by BillKSmith (Prior) on Mar 19, 2020 at 20:35 UTC
    As in your previous question, I use grep to eliminate irrelevant data.
    use strict; use warnings; use Data::Dumper; my $data =[ ... # Ref OP ]; my @extras = grep {$_->{status} eq 'Extra'} @$data; my @mains = grep {$_->{status} eq 'Main' } @$data; MAIN: foreach my $main (@mains) { EXTRA: foreach my $extra (@extras) { next EXTRA if $main->{ID} ne $extra->{ID}; @{$main}{qw/new_name new_ad1 new_city new_z_code/} = @{$extra}{qw/name Ad1 City zCode/}; print Dumper($main); next MAIN; } }

    OUTPUT:

    $VAR1 = { 'ID' => '2222', 'City' => 'NY', 'zCode' => '0002', 'Ad1' => '20 North Central St.', 'name' => 'John D', 'state' => 'TO', 'new_z_code' => '0007', 'new_ad1' => '100 main St.', 'status' => 'Main', 'new_city' => 'BO', 'new_name' => 'Tony Star' }; $VAR1 = { 'zCode' => '2334', 'name' => 'Charles D', 'Ad1' => '12th Street', 'ID' => '1111', 'City' => 'NM', 'new_name' => 'Marie Doe', 'status' => 'Main', 'new_city' => 'MA', 'new_z_code' => '9857', 'state' => 'CA', 'new_ad1' => '44 Dell St' };
    Bill
      Yes, but I also need the other "status = Main" with no Extra related:

      This one, I will have lots of data in that situation:
      $VAR9 = { 'new_City' => '', 'ID' => '8888', 'status' => 'Main', 'name' => 'AKAKAK', 'City' => 'AA', 'state' => 'PP', 'new_ad1' => '', 'Ad1' => '1AAAA', 'new_z_code' => '', 'new_name' => '', 'zCode' => 'TTTT' };
        The $data array is updated. Print any part you want.
        ...# As before my @extras = grep {$_->{status} eq 'Extra'} @$data; my @mains = grep {$_->{status} eq 'Main' } @$data; MAIN: foreach my $main (@mains) { EXTRA: foreach my $extra (@extras) { next EXTRA if $main->{ID} ne $extra->{ID}; @{$main}{qw/new_name new_ad1 new_city new_z_code/} = @{$extra}{qw/name Ad1 City zCode/}; } print Dumper($main); }

        OUTPUT:

        $VAR1 = { 'state' => 'TO', 'new_z_code' => '0007', 'zCode' => '0002', 'status' => 'Main', 'ID' => '2222', 'name' => 'John D', 'City' => 'NY', 'new_city' => 'BO', 'new_ad1' => '100 main St.', 'Ad1' => '20 North Central St.', 'new_name' => 'Tony Star' }; $VAR1 = { 'zCode' => '2334', 'status' => 'Main', 'ID' => '1111', 'state' => 'CA', 'new_z_code' => '9857', 'Ad1' => '12th Street', 'new_name' => 'Marie Doe', 'name' => 'Charles D', 'City' => 'NM', 'new_city' => 'MA', 'new_ad1' => '44 Dell St' }; $VAR1 = { 'City' => 'AA', 'name' => 'AKAKAK', 'state' => 'PP', 'ID' => '8888', 'Ad1' => '1AAAA', 'zCode' => 'TTTT', 'status' => 'Main' };
        Bill
Re: Add new rows and data to array.
by johngg (Canon) on Mar 19, 2020 at 19:56 UTC

    Leaving aside the question of whether you would be better served by a RDBMS, the way you organise your data into a ref. to an array of hashes makes your life rather difficult. To first get an idea of your problem I edited your $data to break it over multiple lines so it was easier to read. It was then clear that a ref. to a hash keyed by "ID" containing sub-hashes keyed by "status" in turn containing sub-sub-hashes with the remaining key/value pairs would make data access and manipulation easier. The data can be remodelled using hash slices rather than having to faff around with each individual key/value pair. There is a useful table on the various ways of accessing data structures here.

    The first part of the code transforms the data into the new form that is easier to manipulate. The second part adds the new keys for those IDs that have an "Extra" sub-hash. Finally we Dumpxs() the resultant data structure. The code:-

    use strict; use warnings; use Data::Dumper; # Original $data edited to make it easier (for my old eyes) to read. # my $dataItems = [ { Ad1 => q{20 North Central St.}, status => q{Main}, City => q{NY}, zCode => q{0002}, name => q{John D}, ID => q{2222}, state => q{TO} }, { Ad1 => q{15 South Street}, status => q{Property}, City => q{NY}, zCode => q{0002}, name => q{John V}, ID => q{2222}, state => q{TO} }, { Ad1 => q{100 main St.}, status => q{Extra}, City => q{BO}, zCode => q{0007}, name => q{Tony Star}, ID => q{2222}, state => q{UA} }, { Ad1 => q{5540 Chelsea Avenue}, status => q{Cabin}, City => q{NE}, zCode => q{4562}, name => q{Carly Simon}, ID => q{2222}, state => q{TO} }, { Ad1 => q{12th Street}, status => q{Main}, City => q{NM}, zCode => q{2334}, name => q{Charles D}, ID => q{1111}, state => q{CA} }, { Ad1 => q{44 Dell St}, status => q{Extra}, City => q{MA}, zCode => q{9857}, name => q{Marie Doe}, ID => q{1111}, state => q{CA} }, { Ad1 => q{33 Dust Road}, status => q{Property}, City => q{ET}, zCode => q{3345}, name => q{Chapim Thor}, ID => q{1111}, state => q{CA} }, { Ad1 => q{01 Charles St}, status => q{Cabin}, City => q{CA}, zCode => q{2334}, name => q{Claud Odur}, ID => q{1111}, state => q{CA} }, { Ad1 => q{1AAAA}, status => q{Main}, City => q{AA}, zCode => q{TTTT}, name => q{AKAKAK}, ID => q{8888}, state => q{PP} }, { Ad1 => q{2AAAA}, status => q{Test}, City => q{BB}, zCode => q{WWWW}, name => q{BXBXBX}, ID => q{8888}, state => q{HH} }, { Ad1 => q{CCCCC}, status => q{Property}, City => q{ET}, zCode => q{3345}, name => q{Chapim Thor}, ID => q{8888}, state => q{CA} }, { Ad1 => q{DDDDD}, status => q{Cabin}, City => q{CA}, zCode => q{2334}, name => q{Claud Odur}, ID => q{8888}, state => q{CA} }, ]; # Re-arrange the reftoAoH $data into a reftoHoHoH $rhByID using hash # slices. # my $rhByID = {}; my @subKeys = qw{ Ad1 City zCode name state }; foreach my $rhItem ( @{ $dataItems } ) { @{ $rhByID->{ $rhItem->{ ID } }->{ $rhItem->{ status } } }{ @subKe +ys } = @{ $rhItem }{ @subKeys }; } # Now add in the new keys and associated values for those IDs that hav +e # a "Extra" sub-key, again using hash slices. I've included "state" in # case it had been omitted from the OP code by mistake. # my @newKeys = qw{ newAd1 newCity newZip newName newState }; foreach my $id ( keys %{ $rhByID } ) { next unless exists $rhByID->{ $id }->{ Extra }; @{ $rhByID->{ $id }->{ Main } }{ @newKeys } = @{ $rhByID->{ $id }->{ Extra } }{ @subKeys }; } # Dump the new data structure. # print Data::Dumper ->new( [ $rhByID ], [ qw{ rhByID } ] ) ->Sortkeys( 1 ) ->Indent( 1 ) ->Dumpxs();

    The output:-

    $rhByID = { '1111' => { 'Cabin' => { 'Ad1' => '01 Charles St', 'City' => 'CA', 'name' => 'Claud Odur', 'state' => 'CA', 'zCode' => '2334' }, 'Extra' => { 'Ad1' => '44 Dell St', 'City' => 'MA', 'name' => 'Marie Doe', 'state' => 'CA', 'zCode' => '9857' }, 'Main' => { 'Ad1' => '12th Street', 'City' => 'NM', 'name' => 'Charles D', 'newAd1' => '44 Dell St', 'newCity' => 'MA', 'newName' => 'Marie Doe', 'newState' => 'CA', 'newZip' => '9857', 'state' => 'CA', 'zCode' => '2334' }, 'Property' => { 'Ad1' => '33 Dust Road', 'City' => 'ET', 'name' => 'Chapim Thor', 'state' => 'CA', 'zCode' => '3345' } }, '2222' => { 'Cabin' => { 'Ad1' => '5540 Chelsea Avenue', 'City' => 'NE', 'name' => 'Carly Simon', 'state' => 'TO', 'zCode' => '4562' }, 'Extra' => { 'Ad1' => '100 main St.', 'City' => 'BO', 'name' => 'Tony Star', 'state' => 'UA', 'zCode' => '0007' }, 'Main' => { 'Ad1' => '20 North Central St.', 'City' => 'NY', 'name' => 'John D', 'newAd1' => '100 main St.', 'newCity' => 'BO', 'newName' => 'Tony Star', 'newState' => 'UA', 'newZip' => '0007', 'state' => 'TO', 'zCode' => '0002' }, 'Property' => { 'Ad1' => '15 South Street', 'City' => 'NY', 'name' => 'John V', 'state' => 'TO', 'zCode' => '0002' } }, '8888' => { 'Cabin' => { 'Ad1' => 'DDDDD', 'City' => 'CA', 'name' => 'Claud Odur', 'state' => 'CA', 'zCode' => '2334' }, 'Main' => { 'Ad1' => '1AAAA', 'City' => 'AA', 'name' => 'AKAKAK', 'state' => 'PP', 'zCode' => 'TTTT' }, 'Property' => { 'Ad1' => 'CCCCC', 'City' => 'ET', 'name' => 'Chapim Thor', 'state' => 'CA', 'zCode' => '3345' }, 'Test' => { 'Ad1' => '2AAAA', 'City' => 'BB', 'name' => 'BXBXBX', 'state' => 'HH', 'zCode' => 'WWWW' } } };

    I don't know whether you are able to modify your data in this way but I really think it would make your life much easier.

    Cheers,

    JohnGG

      I suppose without knowing exactly how the original poster intends to use the data, it's hard to say if this would be better, but might it be even easier to use a multidimensional hash in this case?

      Example:

      %data = ( "1111$;Cabin" => { 'Ad1' => '01 Charles St', 'City' => 'CA', 'name' => 'Claud Odur', 'state' => 'CA', 'zCode' => '2334' }, # ... # snip # ... "8888$;Test" => { 'Ad1' => '2AAAA', 'City' => 'BB', 'name' => 'BXBXBX', 'state' => 'HH', 'zCode' => 'WWWW' } ); # Now elements of the data can be accessed like this my $val = $data{'1111','Cabin'}->{'City'}; # Or, to get a slice of rows where status is 'Main', you could do this +: my @main = @data{grep /$;Main$/, keys %data}

      Edit: Added the line about accessing rows where status 'Main'

Re: Add new rows and data to array.
by kcott (Bishop) on Mar 20, 2020 at 01:43 UTC

    In the following code, I've cut down the input data to the minimum required to demonstrate the technique that I've used.

    #!/usr/bin/env perl use strict; use warnings; use Data::Dump; my $data = [ { status => 'Main', City => 'NY', zCode => '0002', ID => '2222' } +, { status => 'Extra', City => 'BO', zCode => '0007', ID => '2222' } +, { status => 'Cabin', City => 'NE', zCode => '4562', ID => '2222' } +, { status => 'Main', City => 'AA', zCode => 'TTTT', ID => '8888' } +, { status => 'Test', City => 'BB', zCode => 'WWWW', ID => '8888' } +, { status => 'Cabin', City => 'CA', zCode => '2334', ID => '8888' } +, ]; my %new = (City => 'new_City', zCode => 'new_z_code'); my %extra; $extra{$_->{ID}} = $_ for grep +($_->{status} eq 'Extra'), @$data; for my $row (@$data) { next unless $row->{status} eq 'Main'; %$row = (%$row, map +($new{$_} => exists $extra{$row->{ID}} ? $extra{$row->{ID}}{$_} : '' ), keys %new ); } dd $data;

    Output:

    [ { City => "NY", ID => 2222, new_City => "BO", new_z_code => "0007", status => "Main", zCode => "0002", }, { City => "BO", ID => 2222, status => "Extra", zCode => "0007" }, { City => "NE", ID => 2222, status => "Cabin", zCode => 4562 }, { City => "AA", ID => 8888, new_City => "", new_z_code => "", status => "Main", zCode => "TTTT", }, { City => "BB", ID => 8888, status => "Test", zCode => "WWWW" }, { City => "CA", ID => 8888, status => "Cabin", zCode => 2334 }, ]

    You should only need to add two key-value pairs to %new for a full solution.

    Consider simply adding 'new_' to the existing keys for a more standard naming convention. This would make comparing keys easier; if not a requirement now, it could be at a later date. It would also allow you to simplify my code, as follows:

    my @new = qw{City zCode ...}; ... map +("new_$_" => exists ... ), @new

    — Ken

Re: Add new rows and data to array.
by clueless newbie (Deacon) on Mar 19, 2020 at 22:15 UTC

    Indexing first might make things easier.

    #!/usr/bin/perl use Data::Alias; use Data::Dumper; use 5.01800; use warnings; use Data::Dumper; my $data =[ { Ad1 => '20 North Central St.', status => 'Main', City => 'NY +', zCode => '0002', name => 'John D', ID => '2222', state => 'T +O' }, { Ad1 => '15 South Street', status => 'Property', City => 'NY +', zCode => '0002', name => 'John V', ID => '2222', state => 'T +O' }, { Ad1 => '100 main St.', status => 'Extra', City => 'BO +', zCode => '0007', name => 'Tony Star', ID => '2222', state => 'U +A' }, { Ad1 => '5540 Chelsea Avenue', status => 'Cabin', City => 'NE +', zCode => '4562', name => 'Carly Simon', ID => '2222', state => 'T +O' }, { Ad1 => '12th Street', status => 'Main', City => 'NM +', zCode => '2334', name => 'Charles D', ID => '1111', state => 'CA +' }, { Ad1 => '44 Dell St', status => 'Extra', City => 'MA +', zCode => '9857', name => 'Marie Doe', ID => '1111', state => 'C +A' }, { Ad1 => '33 Dust Road', status => 'Property', City => 'ET +', zCode => '3345', name => 'Chapim Thor',ID => '1111', state => 'CA +' }, { Ad1 => '01 Charles St', status => 'Cabin', City => 'CA +', zCode => '2334', name => 'Claud Odur', ID => '1111', state => 'CA +' }, { Ad1 => '1AAAA', status => 'Main', City => 'AA', zCode => 'T +TTT', name => 'AKAKAK', ID => '8888', state => 'PP' }, { Ad1 => '2AAAA', status => 'Test', City => 'BB', zCode => 'W +WWW', name => 'BXBXBX', ID => '8888', state => 'HH' }, { Ad1 => 'CCCCC', status => 'Property', City => 'ET', zCode => '3 +345', name => 'Chapim Thor', ID => '8888', state => 'CA' }, { Ad1 => 'DDDDD', status => 'Cabin', City => 'CA', zCode => '2 +334', name => 'Claud Odur', ID => '8888', state => 'CA' }, ]; my $index={}; for (@$data) { if ($_->{status} eq 'Main') { $index->{$_->{ID}}{Main}=$_; } elsif ($_->{status} eq 'Extra') { $index->{$_->{ID}}{Extra}=$_; }; }; $Data::Dumper::Sortkeys=1; warn Data::Dumper->Dump([\$data,\$index],[qw(*data *index)]),' '; for my $key (keys %$index) { if (exists $index->{$key}{Main} && exists $index->{$key}{Extra}) { # We have a candidate for merging alias my $candidate=$index->{$key}; warn Data::Dumper->Dump([\$candidate],[qw(*candidate)]),' '; for my $item (keys %{$candidate->{Extra}}) { # next for items you don't want moved #next # if ($item =~ m{status}); $candidate->{Main}{"new_$item"}=delete $candidate->{Extra +}{$item}; }; }; }; warn Data::Dumper->Dump([\$data],[qw(*data)]),' ';

    yields:

    $data = \[ { 'Ad1' => '20 North Central St.', 'City' => 'NY', 'ID' => '2222', 'name' => 'John D', 'state' => 'TO', 'status' => 'Main', 'zCode' => '0002' }, { 'Ad1' => '15 South Street', 'City' => 'NY', 'ID' => '2222', 'name' => 'John V', 'state' => 'TO', 'status' => 'Property', 'zCode' => '0002' }, { 'Ad1' => '100 main St.', 'City' => 'BO', 'ID' => '2222', 'name' => 'Tony Star', 'state' => 'UA', 'status' => 'Extra', 'zCode' => '0007' }, { 'Ad1' => '5540 Chelsea Avenue', 'City' => 'NE', 'ID' => '2222', 'name' => 'Carly Simon', 'state' => 'TO', 'status' => 'Cabin', 'zCode' => '4562' }, { 'Ad1' => '12th Street', 'City' => 'NM', 'ID' => '1111', 'name' => 'Charles D', 'state' => 'CA', 'status' => 'Main', 'zCode' => '2334' }, { 'Ad1' => '44 Dell St', 'City' => 'MA', 'ID' => '1111', 'name' => 'Marie Doe', 'state' => 'CA', 'status' => 'Extra', 'zCode' => '9857' }, { 'Ad1' => '33 Dust Road', 'City' => 'ET', 'ID' => '1111', 'name' => 'Chapim Thor', 'state' => 'CA', 'status' => 'Property', 'zCode' => '3345' }, { 'Ad1' => '01 Charles St', 'City' => 'CA', 'ID' => '1111', 'name' => 'Claud Odur', 'state' => 'CA', 'status' => 'Cabin', 'zCode' => '2334' }, { 'Ad1' => '1AAAA', 'City' => 'AA', 'ID' => '8888', 'name' => 'AKAKAK', 'state' => 'PP', 'status' => 'Main', 'zCode' => 'TTTT' }, { 'Ad1' => '2AAAA', 'City' => 'BB', 'ID' => '8888', 'name' => 'BXBXBX', 'state' => 'HH', 'status' => 'Test', 'zCode' => 'WWWW' }, { 'Ad1' => 'CCCCC', 'City' => 'ET', 'ID' => '8888', 'name' => 'Chapim Thor', 'state' => 'CA', 'status' => 'Property', 'zCode' => '3345' }, { 'Ad1' => 'DDDDD', 'City' => 'CA', 'ID' => '8888', 'name' => 'Claud Odur', 'state' => 'CA', 'status' => 'Cabin', 'zCode' => '2334' } ]; $index = \{ '1111' => { 'Extra' => ${$data}->[5], 'Main' => ${$data}->[4] }, '2222' => { 'Extra' => ${$data}->[2], 'Main' => ${$data}->[0] }, '8888' => { 'Main' => ${$data}->[8] } }; at 11114482.t line 41. $candidate = \{ 'Extra' => { 'Ad1' => '100 main St.', 'City' => 'BO', 'ID' => '2222', 'name' => 'Tony Star', 'state' => 'UA', 'status' => 'Extra', 'zCode' => '0007' }, 'Main' => { 'Ad1' => '20 North Central St.', 'City' => 'NY', 'ID' => '2222', 'name' => 'John D', 'state' => 'TO', 'status' => 'Main', 'zCode' => '0002' } }; at 11114482.t line 47. $candidate = \{ 'Extra' => { 'Ad1' => '44 Dell St', 'City' => 'MA', 'ID' => '1111', 'name' => 'Marie Doe', 'state' => 'CA', 'status' => 'Extra', 'zCode' => '9857' }, 'Main' => { 'Ad1' => '12th Street', 'City' => 'NM', 'ID' => '1111', 'name' => 'Charles D', 'state' => 'CA', 'status' => 'Main', 'zCode' => '2334' } }; at 11114482.t line 47. $data = \[ { 'Ad1' => '20 North Central St.', 'City' => 'NY', 'ID' => '2222', 'name' => 'John D', 'new_Ad1' => '100 main St.', 'new_City' => 'BO', 'new_ID' => '2222', 'new_name' => 'Tony Star', 'new_state' => 'UA', 'new_status' => 'Extra', 'new_zCode' => '0007', 'state' => 'TO', 'status' => 'Main', 'zCode' => '0002' }, { 'Ad1' => '15 South Street', 'City' => 'NY', 'ID' => '2222', 'name' => 'John V', 'state' => 'TO', 'status' => 'Property', 'zCode' => '0002' }, {}, { 'Ad1' => '5540 Chelsea Avenue', 'City' => 'NE', 'ID' => '2222', 'name' => 'Carly Simon', 'state' => 'TO', 'status' => 'Cabin', 'zCode' => '4562' }, { 'Ad1' => '12th Street', 'City' => 'NM', 'ID' => '1111', 'name' => 'Charles D', 'new_Ad1' => '44 Dell St', 'new_City' => 'MA', 'new_ID' => '1111', 'new_name' => 'Marie Doe', 'new_state' => 'CA', 'new_status' => 'Extra', 'new_zCode' => '9857', 'state' => 'CA', 'status' => 'Main', 'zCode' => '2334' }, {}, { 'Ad1' => '33 Dust Road', 'City' => 'ET', 'ID' => '1111', 'name' => 'Chapim Thor', 'state' => 'CA', 'status' => 'Property', 'zCode' => '3345' }, { 'Ad1' => '01 Charles St', 'City' => 'CA', 'ID' => '1111', 'name' => 'Claud Odur', 'state' => 'CA', 'status' => 'Cabin', 'zCode' => '2334' }, { 'Ad1' => '1AAAA', 'City' => 'AA', 'ID' => '8888', 'name' => 'AKAKAK', 'state' => 'PP', 'status' => 'Main', 'zCode' => 'TTTT' }, { 'Ad1' => '2AAAA', 'City' => 'BB', 'ID' => '8888', 'name' => 'BXBXBX', 'state' => 'HH', 'status' => 'Test', 'zCode' => 'WWWW' }, { 'Ad1' => 'CCCCC', 'City' => 'ET', 'ID' => '8888', 'name' => 'Chapim Thor', 'state' => 'CA', 'status' => 'Property', 'zCode' => '3345' }, { 'Ad1' => 'DDDDD', 'City' => 'CA', 'ID' => '8888', 'name' => 'Claud Odur', 'state' => 'CA', 'status' => 'Cabin', 'zCode' => '2334' } ]; at 11114482.t line 53.

    Note the now empty (formerly Extra) hashes resulting from the use of delete.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11114482]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2020-04-04 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (32 votes). Check out past polls.

    Notices?