I'm not sure those are the only two ways to look at it. Lots of different data types can be passed to a subroutine and the way perl handles them does seem to work well for a number of projects that need a slightly less restricted method (e.g. BioPerl). Works really well when most of the variables you might pass are optional and you don't want to have to feed in the default option when you want it to just be default to get to a variable that you do want to change.

It appears that is the closest possible syntax fro what I want to do,
I suppose if I'm going to write in perl I'll just have to get over
wanting to do things the way I like and embrace the way perl does
things, although I'll likely never understand why anyone would rather
have shorter code than more readable code.

On Fri, Jul 9, 2010 at 10:28 AM, Dale Farnsworth<d...@farnsworth.org>  wrote:
I'm working on a perl script, and I have a lot more experience in ruby
than I do in perl.  As far as I can tell there is no way to explicitly
define arguments for a subroutine in perl, for example

sub addNums(number1, number2) {
   sum = number1 + number2;

   return sum;
}

rather than

sub addNums {
   number1 = shift;
   number2 = shift;
   sum = number1 + number2;

   return sum;
}

is there anyway to do this, and if not does anyone have some advice on
a way to make this a bit more readable in perl?

It's been a while since I programmed in perl.  I currently use python
after going through a long ruby phase.

However, I think the canonical way to do it is:

sub addNums($$) {
  my ($number1, $number2) = @_;
  my $sum = $number1 + $number2;

  return $sum;
}

-Dale
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

Reply via email to