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

Problem with undifined value as an ARRAY reference

by mrras25 (Acolyte)
on Jul 17, 2013 at 23:47 UTC ( #1044927=perlquestion: print w/ replies, xml ) Need Help??
mrras25 has asked for the wisdom of the Perl Monks concerning the following question:

I have this block of code:
# Build Host to Storage relationship and enter into database my %remove_dups; foreach my $host(keys %{$build_dwh{'h2s'}}) { my ($storID,$lcstorage,$lcalias); foreach my $keys(keys %{$build_dwh{'h2s'}{$host}}) { foreach my $arrayID (@{$build_dwh{'h2s'}{$host}{$keys}}) { my $lchost = lc($host); my $lcstor = lc($arrayID); my $cmpOne = $rtrn_prdb_id{'storage'}{$lcstor}; my $cmpTwo = $rtrn_prdb_id{'serial'}{$lcstor}; my $storID = ($cmpOne ? $cmpOne : $cmpTwo); if($storID) { my $htcref = join(".",$rtrn_prdb_id{'host'}{$lchost},$stor +ID); if(!$rtrn_prdb_id{'hTSId'}{$htcref}) { push @{$remove_dups{$storID}}, $rtrn_prdb_id{'host'}{$l +chost}; # push @h2s, [$rtrn_prdb_id{'host'}{$lchost},$storID]; } } } } } #processH2sLoad(@h2s); my %rebuild_h2s; foreach my $storArr(%remove_dups) { my %seen =() ; my @unique_array = grep { ! $seen{$_}++ } @{$remove_dups{$storArr}} +; $rebuild_h2s{$storArr} = \@unique_array; } foreach my $storArr(%rebuild_h2s) { my @shift_load = @{$rebuild_h2s{$storArr}}; #<--- Error Here for(my $i = 0; $i <=$#shift_load; $i++) { push @h2s, [$shift_load[$i],$storArr]; } }
it causes this error
Can't use an undefined value as an ARRAY reference at TEMP_load_OCI_Ho +stData_Complete.pl line 393.
when I dump the hash I get the following:
$VAR1 = 'ARRAY(0xdf95524)'; #<--- Can't get rid of this shouldn't be h +ere $VAR2 = []; $VAR3 = '102'; $VAR4 = [ '10045475', '10045476', '10045477', '10045478', '10045479', '10045480', '10045482', '10045481', '10045483', '10045484', '10045485', '10045486', '10045487', '10045488', '10045489', '10045490', '10045492', '10045491', '10045494', '10045493', '10045496', '10045495' ]
but not sure how to get rid of it;

Comment on Problem with undifined value as an ARRAY reference
Select or Download Code
Re: Problem with undifined value as an ARRAY reference
by Anonymous Monk on Jul 18, 2013 at 00:04 UTC
Re: Problem with undifined value as an ARRAY reference
by dave_the_m (Parson) on Jul 18, 2013 at 00:07 UTC
    foreach my $storArr(%rebuild_h2s)
    should be
    foreach my $storArr(keys %rebuild_h2s)

    (I don't know whether that's your only issue, but its the one that leap out at me.)

    Dave.

      Thanks Dave can't believe I missed that... been coding for 36 hours straight here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-31 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls