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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.