R
Ronny
Assume that I have a function f expecting a list of arguments, and an
expression
E returning a list. Of course one way to call this function is just:
f(E)
Example: f(`ls -l foo`);
Now suppose that I want to pass to the function only the first $n
elements of E.
A naive approach (assuming $n > 0) would be
f((E)[0..($n-1)])
but this raises error messages if E contains less than $n elements. One
way out
from this dilemma would be the introduction of an auxiliary array:
my @temp=(E);
f(@temp[0..($n > $#temp ? $#temp : $n-1)]);
Needless to say that this is a very ugly solution. Can someone suggest
a more
elegant way?
Ronald
expression
E returning a list. Of course one way to call this function is just:
f(E)
Example: f(`ls -l foo`);
Now suppose that I want to pass to the function only the first $n
elements of E.
A naive approach (assuming $n > 0) would be
f((E)[0..($n-1)])
but this raises error messages if E contains less than $n elements. One
way out
from this dilemma would be the introduction of an auxiliary array:
my @temp=(E);
f(@temp[0..($n > $#temp ? $#temp : $n-1)]);
Needless to say that this is a very ugly solution. Can someone suggest
a more
elegant way?
Ronald