Reply to post: Re: Functions returning multiple values.

Mads Torgersen and Dustin Campbell on the future of C#

Frumious Bandersnatch

Re: Functions returning multiple values.

Perl subs (and some builtins) have this too, via the ability to return a list. You can aid readability firstly by properly documenting the calling convention, but also by using constants to simulate enums. For example:

use strict;

use warnings;

use constant {

Dev => 0, Ino => 1, Mode => 2, Nlink =>3, Uid => 4, Gid => 5, Rdev => 6,

Size =>7, Atime => 8, Mtime => 9, Ctime => 10, Blksize => 11, Blocks => 7

};

print "This dir's mode is ", (stat ".")[Mode], "\n";

Of course, Perl is a pretty pathological language. You can even modify the type of thing returned (via something like wantarray) depending on the calling context. Loads of scope to shoot yourself in the foot.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon