Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Overwriting Hash / Array

by kcott (Archbishop)
on Jul 28, 2015 at 09:51 UTC ( [id://1136573]=note: print w/replies, xml ) Need Help??


in reply to Overwriting Hash / Array

G'day iRemix94,

I see you found out what the problem is.

"Any tip how to not overwrite the entries?"

Yes.

Change lines that look like this:

push @array, \%hash

To lines that look more like this:

push @array, {%hash}

Similarly, change '\@array' to '[@array]', where appropriate.

— Ken

Replies are listed 'Best First'.
Re^2: Overwriting Hash / Array
by iRemix94 (Sexton) on Jul 28, 2015 at 10:21 UTC

    sadly, I still don't know how to fix the proplem .. As I've understood it, I have to declare the hash inside the loop that gets the information, but with it, I have to put the "push" line into that loop aswell, which gives me not the wished output.

      I've refactored your code slightly and I hope you can see how the act loop is setting the same hash element each time. Add the $debug variable to see. What structure do you want ?

      foreach my $i ( 1 .. $scheduled_export_days ){ my %column_data_export; my %column_data_import; $column_data_export{SCHEDULE} = $schedule_hour; $column_data_export{UNDEF} = 1; my $debug=0; for my $act (@{$bi->{$customer}->{$domain}->{$host}->{BACKUPDATA}}){ + ++$debug; my $imp_exp_type = $act->{ACTION_TYPE}; my $imp_exp_status = $act->{STATUS}; my @schedule_time = split(/:/, $schedule_hour); my $minutes_range = ($schedule_time[1]+30) % 60; # import code if ($imp_exp_type eq "IMPORT"){ my ($imp_formated_hour,undef) = hhmm($act->{ENDDATE_SEC},$unit) $column_data_import{SCHEDULE} = $imp_formated_hour; $column_data_import{UNDEF} = $debug ;#1 ; } # export code } push (@columns_export, \%column_data_export); push (@columns_import, \%column_data_import); } sub hhmm { my ($s,$unit) = @_; my @tmp = split / /,$unit->formatDateTime($s); my ($hr,$min) = split /:/, $tmp[1]; return ("$hr:$min",$tmp[0]); }
      poj

        my wished structure is like the dumper result in my original post. As you can see there, the SCHEDULE_COLUMNS_IMPORT has several entries. The schedule value here should display the value of $imp_formated_hour from all the existing export reports. So it should basically be the same as the SCHEDULE_COLUMNS_EXPORT, just with other schedule_values. The difference here is, the schedule value for the export reports are gathered in a loop before. Not like the schedule values of the import reports. I don't know how I can change my code so that it doesn't overwrite the hash all the time .. sorry, my PERL knowledge is still very lacking :/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found