Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Iterating though an array of objects

by moritz (Cardinal)
on Aug 27, 2012 at 12:35 UTC ( #989979=note: print w/replies, xml ) Need Help??


in reply to Iterating though an array of objects

You should really format your code better (one indetion level per opneing brace, see perlstyle), it is very hard to read as is. Maybe the problem becomes visible then?

One obvious problem is:

sub scores { my ( $self, @scores )= @_; ... } # and later $node->scores(['3','177','12',]);

The scores method expcets a flat list, but you pass an array reference to it.

Also dubious:

eval{person->new();} or die ($@);

Why catch errors with eval if all you do is rethrowing them?

Replies are listed 'Best First'.
Re^2: Iterating though an array of objects
by chromatic (Archbishop) on Aug 27, 2012 at 16:23 UTC
    Why catch errors with eval if all you do is rethrowing them?

    What if the constructor returned a false value? (It doesn't, but it could.) Then again, the exception message would be awful.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989979]
help
Chatterbox?
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation
[Discipulus]: and in the wanted sub you just calculate the duretion and add it the total, stop
[shmem]: sub wanted { push @files, $File::Find::name if $File::Find::name =~/\.mp3$/ }
[Lady_Aleena]: shmem, that is understandable! The two examples in File::Find don't make sense to me on a quick glance.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-04-23 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.