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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |