Impossible. You're asking to do something that's the very definition of looping without using a loop. What do you actually want?
At university I learned that loops can be replaced by recursivity. So the simple code below fulfills the requirements of the OP (one line, no loop) ... but maybe isn't what he wants. ;-)
However this statement stems from a course of theoretical computer science. Don't use the code below in a productive environment. It is slower and takes much more resources than the other, straightforward solutions presented in this thread!
You have been warned! Rata
use strict; use warnings; my @x = qw ( a b c d e ff ggg hhhh iiii ); my %y; # Tata!!! Here comes the requested line of code: noLoop(); sub noLoop { $y{pop(@x)} = 1; noLoop() if (scalar(@x)); } # + btw.: using global vars in subs is usually bad style ;-) print keys(%y), "\n"; exit 0;
In reply to Re^2: use array for hash-keys without loop
by Ratazong
in thread use array for hash-keys without loop
by piccard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |