Anon Array

Discussion in 'Perl' started by The Owner, Feb 26, 2009.

  1. The Owner

    The Owner Guest

    Hi,

    I'm looking for a better way to use the contents of an anonymous array.
    This is what I've done so far:

    #!/usr/bin/perl
    #

    use strict;
    use Data::Dumper;

    my (%test,@numbers,$key,$value,$index);

    @numbers = (1,2,3);

    $test{"base_0"} = [ @numbers ];
    print STDOUT ("test\{\"base_0\"\}= ".Dumper($test{"base_0"})."\n");
    $test{"base_10"} = [ map ($_+10, @numbers)];
    print STDOUT ("test\{\"base_10\"\}= ".Dumper($test{"base_10"})."\n");

    foreach $key (sort keys (%test))
    {
    print STDOUT ("ref\(test\{$key\}\)= ".ref($test{$key})."\n");
    $index = 0;
    until (!$test{$key}[$index])
    {
    print STDOUT ("value\[$index\]= ".$test{$key}[$index]."\n");
    $index ++;
    }
    }

    It's kinda ugly to do it this way. Any suggestion(s)? Thanks.
     
    The Owner, Feb 26, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.