in reply to Passing Any Range of Values to a Sub

Hi there.

I'm also a student learning the language.

Personally, I think it's best to always use:

my $size = scalar(@testarr);

rather than:

my $size = @testarr;

Because it's easier to understand and by naming something you exert a little more control over it. It also helps stress the difference between scalars and arrays, which is helpful for me as a student.

I'd be interested in knowing what the more established users of the language think about using scalar() rather than using only the array.

Any comments?

David Caughell.
Barrie, Ontario, Canada.

  • Comment on Re: Passing Any Range of Values to a Sub

Replies are listed 'Best First'.
Re: Re: Passing Any Range of Values to a Sub
by chromatic (Archbishop) on Jul 02, 2003 at 05:53 UTC

    If it's clearer for you and the people you work with, go ahead and use it. Maintainability and clear communication trump just about any other concern.

    I personally don't care for it because I'm used to context. It's effectively a no-op, and, if I don't have to worry about the maintainability burden to someone who doesn't have a firm grip on context (and I usually don't), I prefer to leave out unnecessary code.

    You'll probably find yourself using it less and less often as you continue learning.

      That makes sense, thanks a lot!

      I'd prefer to send a message like this privately, but I don't think I can do that. If there's a way of sending PMs here, someone please send me one and let me know!! :)

      Update: to send someone a private message, just type /msg username message in the chatter box and hit "talk".

      --Dave