perl177 has asked for the wisdom of the Perl Monks concerning the following question:

my sample Array is @array= (loga1,loga2,logb1,logb2 ...) . Any operator or function to declare the array something like @array =log [a,b ] [1 ..7 ] instead of listing each value .I am only willing to populate the values inside the array and I am not comparing ,its just declaring . Thanks in advance for your help

Replies are listed 'Best First'.
Re: Declare values in array using Regex
by JavaFan (Canon) on Feb 10, 2009 at 22:06 UTC
    Perhaps something like:
    @array = map {"log$_"} map {my $s = $_; map {"$_$s"} qw [a b]} 1 .. 7;
      Oh , thanks a lot ...it just worked like a miracle

        I believe it is known as magic, actually. :P

        And you didn't even know bears could type.

Re: Declare values in array using Regex
by almut (Canon) on Feb 10, 2009 at 22:11 UTC

    You could (mis)use glob():

    my @array = glob "log{a,b}{1,2,3}"; print "@array\n"; # loga1 loga2 loga3 logb1 logb2 logb3
Re: Declare values in array using Regex
by ikegami (Patriarch) on Feb 10, 2009 at 22:15 UTC
    Yet another way:
    use Algorithm::Loops qw( NestedLoops ); my @lists = ( [qw( a b )], [ 1..7 ], ); my @array = NestedLoops(\@lists, sub { 'log' . join('', @_) });

    It's bigger, but it's very dynamic.