views:

81

answers:

2

I have got as follows:

 use constant ABC => ('one', 'two', 'three');

and I want to pass this constant to variations_with_repetition(\@data, $k) subroutine as @data.

How should I do that?

+7  A: 

Use the [] operator to convert a list to an ARRAY reference:

variations_with_repetition( [ABC] , $k );
mobrule
A: 

You can try this:

use strict;
use warnings;

use constant ABC => ('one', 'two', 'three');

sub foo {
    my $list = shift;
    die if ( $list->[0] ne 'one' );
    die if ( $list->[1] ne 'two' );
    die if ( $list->[2] ne 'three');
}

my @data = ABC;

foo \@data;
Kivin
Frankly, if you are going to do this, why bother passing any arguments to the function at all? I am afraid you are missing something very crucial in your understanding of programming.
Sinan Ünür