len

R

Robin

what would this do?

sub array_abslen

{

my (@array) = @_;

my ($len);

$len = @array;

$len = $len - 1;

return ($len);

}

thanks,

-Robin
 
G

Gunnar Hjalmarsson

Robin said:
what would this do?

sub array_abslen
{
my (@array) = @_;
my ($len);
$len = @array;
$len = $len - 1;
return ($len);
}

The same as

sub array_abslen { @_ - 1 }
 
R

Ragnar Hafstað

Robin said:
what would this do?

sub array_abslen
defines function
{

my (@array) = @_;
the function takes an array (or list) as argument
my ($len);

$len = @array;
this is the number of elements in the array (list)
$len = $len - 1;
substract one
return ($len);
return that

in other words this is a rather long-winded way to calculate one less
than the numbers of elements in an array/list

I could mention $#x, but i will not bother.
you are welcome

gnari
 
M

Matt Garrish

Robin said:
what would this do?

sub array_abslen

{

my (@array) = @_;

my ($len);

$len = @array;

$len = $len - 1;

return ($len);

}

thanks,

It's a rather long and pointless way of checking $#array. Arrays start at 0,
so if you want the last element in the array you get the length (total
number of entries) and subtract one.

Matt
 
T

Tad McClellan

Gunnar Hjalmarsson said:
The same as

sub array_abslen { @_ - 1 }


and also the same as:

sub array_abslen { $#_ }


(as long as you haven't done anything that you shouldn't have.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,369
Latest member
FTMZ

Latest Threads

Top