Hey all,
I have a fairly simple issue. I'm passing a subroutine an unknown number of variables in groups of three. For example, I might be passing it:
mySub($hello, 5, $goodbye, 'asdf', 6, 'fdsa');
or
mySub('asdf, 6, 'fdsa');
I figured I'd be slick and arrange the function to take the parameters in groups of three until none were left, using shift:
sub mySub {
while((my $string1, my $dist, my $string2) = (shift, shift, shift)) {
# process
}
}
But, this loops endlessly, even when shift is returning nothing. I'm aware of ways around this, but I'd really like a one-liner if at all possible (some variation of the above while loop?).
Thanks,
Nick
I have a fairly simple issue. I'm passing a subroutine an unknown number of variables in groups of three. For example, I might be passing it:
mySub($hello, 5, $goodbye, 'asdf', 6, 'fdsa');
or
mySub('asdf, 6, 'fdsa');
I figured I'd be slick and arrange the function to take the parameters in groups of three until none were left, using shift:
sub mySub {
while((my $string1, my $dist, my $string2) = (shift, shift, shift)) {
# process
}
}
But, this loops endlessly, even when shift is returning nothing. I'm aware of ways around this, but I'd really like a one-liner if at all possible (some variation of the above while loop?).
Thanks,
Nick