Hi all! I'm a new Perl programmer and I'm trying to output combinations of numbers (1 to 10) to a file, but all I can get as output is a list of "ARRAY(0x4eeeec)" (for instance), both in the screen and written on the file. I've searched a little all over the place (Perl Monks included) but I can't find a similar situation / problem. Since I'm a new Perl user, I think my code is printing not an actual value but an address - I guess I'm misusing the iterator, but I can't find out why and how to fix it. Any help will be greatly appreciated. Thanks, Joćo Fernandes

#!/usr/bin/perl use strict; use warnings; use Algorithm::Combinatorics qw(combinations); my @data = qw(1 2 3 4 5 6 7 8 9 10); my $k = 4; open(my $output, ">", "combinations.txt") or die "Can't open combinati +ons.txt: $!"; my $iter = combinations(\@data, $k); while (my $combination = $iter->next) { print "$combination\n"; print $output "$combination\n"; } close $output or die "$output: $!";

In reply to Misprinting combinations / iterator by blacknail

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.