Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
glob to the rescue? glob can generate string combinations/permutations in many cases, depending on your needs.
#!/your/perl/here use strict; use warnings; my %line = ('A' =>1, 'B' =>1, 'C' =>1); # last combination to emit (based on grep filter) my $last = 'AYW'; # build up strings for use with glob() my @line_keys = sort keys %line; my @tojoin = sort ('', qw (W X Y Z)); my $line_keys = join ',', @line_keys; my $tojoin = join ',', @tojoin; # alternation in glob uses '{string1,string2,...}' my $glob = '{' . join( '}{', $line_keys, $tojoin, $tojoin ) . '}'; # globbing @glob = glob $glob; # only keep strings shorter than $last, # or le $last my @glob = grep length($_) < length($last) || $_ le $last, @glob; # populate hash (easier ways???) @line{@glob} = (1) x @glob; # print results (note sort sub) foreach my $key (sort string_length keys %line) { print "$key => $line{$key}\n"; } # sort by length, then lexicographically sub string_length { length($a) <=> length($b) or $a cmp $b }
A => 1 B => 1 C => 1 AW => 1 AX => 1 AY => 1 AZ => 1 BW => 1 BX => 1 BY => 1 BZ => 1 CW => 1 CX => 1 CY => 1 CZ => 1 AWW => 1 AWX => 1 AWY => 1 AWZ => 1 AXW => 1 AXX => 1 AXY => 1 AXZ => 1 AYW => 1

Quantum Mechanics: The dreams stuff is made of

In reply to Re: Updating A Hash Recursively by QM
in thread Updating A Hash Recursively by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2020-06-02 16:00 GMT
    Find Nodes?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?

      Results (19 votes). Check out past polls.