http://qs321.pair.com?node_id=193998


in reply to [untitled node, ID 193991]

If you are not sure of the number of args, just assign to an array

sub foo { my (@args) = @_; }

Why not use @_ directly, you may ask? Well, first, @_ has magical powers. Second, it's less readable.

In fact, ask yourself why the sub has a variable number of args - is it trying to do to much? If so, then maybe you ought to consider breaking the function down into smaller bits with more clearly defined purposes

If the function has a clear need for multiple args, it may still be true that the first couple of args have a defined purpose and the remainder of the args define a variable length additional data. In that case, consider naming those important initial args in a useful way, leaving the remainder in a list.

sub foo_which_processes_a_list { my ( $employee_name, @tasks) = @_; }

This has the added benefit of promoting useful information out of the collection of the list to a more important looking scalar

Cheers,
Erik

Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet