blacknail has asked for the wisdom of the Perl Monks concerning the following question:
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: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Misprinting combinations / iterator
by tangent (Parson) on Mar 27, 2012 at 15:36 UTC | |
by blacknail (Initiate) on Mar 27, 2012 at 16:01 UTC | |
|
Re: Misprinting combinations / iterator
by moritz (Cardinal) on Mar 27, 2012 at 15:36 UTC | |
by blacknail (Initiate) on Mar 27, 2012 at 15:59 UTC | |
|
Re: Misprinting combinations / iterator
by Marshall (Canon) on Mar 27, 2012 at 15:54 UTC | |
by blacknail (Initiate) on Mar 27, 2012 at 16:03 UTC | |
by Marshall (Canon) on Mar 27, 2012 at 20:18 UTC |