Great! Here's the same rewritten into Moose.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package Employee; use Moose; use Function::Parameters; use namespace::clean; has name => (is => 'ro', isa => 'Str'); has hourly_wage => (is => 'ro', isa => 'Int'); has hours => (is => 'ro', isa => 'Int'); method pay () { $self->hours * $self->hourly_wage } method gist () { "Employee info: name: " . $self->name . " hours: " . $self->hours . " wage: " . $self->hourly_wage . "\n" } __PACKAGE__->meta->make_immutable } { package EmployeeList; use Moose; use Function::Parameters; use List::Util qw{ sum0 }; use namespace::clean; has employee_list => (is => 'ro', isa => 'ArrayRef[Employee]', traits => ['Array'], handles => { add_employee => 'push', list_employees => 'elements', }, ); method gist () { join "", map $_->gist, $self->list_employees } method average_hourly_wage () { sum0(map $_->hourly_wage, $self->list_employees) / $self->list_employees } method find ($name) { (grep $_->name eq $name, $self->list_employees)[0] } __PACKAGE__->meta->make_immutable } print 'Enter the name of the file to open: '; chomp( my $input_file = <STDIN> ); open my $file_handle, '<', $input_file or die "Failed to open $input_file: $!\n"; my $employee_list= 'EmployeeList'->new; while (my $row = <$file_handle>) { my @splitrow = split ' ', $row; my $employee = 'Employee'->new( name => $splitrow[0], hourly_wage => $splitrow[1], hours => $splitrow[2] ); $employee_list->add_employee($employee); } print $employee_list->gist; say $employee_list->average_hourly_wage; say $employee_list->find('holli')->pay;
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re^2: Newbie question under time constraint by choroba
in thread Newbie question under time constraint by crazedrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.