in reply to Re^3: Newbie question under time constraint
in thread Newbie question under time constraint

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^4: Newbie question under time constraint

Replies are listed 'Best First'.
Re^5: Newbie question under time constraint
by holli (Abbot) on Aug 04, 2019 at 21:14 UTC
    The only way this (my) code can throw a division by zero error is when you tell the program to read an empty data file. This can be mitigated.
    sub average_hourly_wage{ my $self = shift; my $wages = 0; my $count = 0; foreach my $employee ( @{ $self->{EmployeeList} }) { $wages += $employee->{hourlywage}; $count++; } return $count ? $wages / $count : 0; }
    And of course, if the data file is empty, there is nothing in the Employee-List, thus ->find returns undef. That however, is something you have to deal with in the calling code.
    if ( my $e = $EmployeeList->find("holli") ) { print $e->pay, "\n"; } else { print "User not found\n"; }


    holli

    You can lead your users to water, but alas, you cannot drown them.
    A reply falls below the community's threshold of quality. You may see it by logging in.