Thank you for your answer, however I think you have misunderstood my
problem. I needed to loop over the $groupX in @table while interpolating
the ip addresses from %vars and displaying the table name.
But I finally got it to work :-)

I was looking for this kind of lines :

for my $table (@tables) {
    for (0 .. (scalar (@{ $table->{ips} })) - 1) {
        print $table->{tablename} . ',';
        print $vars{$table->{ips}[$_]};
    }
}


Thank you anyway



Le 17/02/2016 12:54, Rui Fernandes a écrit :
> Hi,
> 
> Try this (read comments please...)
> 
> #!/usr/bin/perl
> 
> print "Content-type: text/html\n\n";
> 
> 
> my $VAR1 = {
>           'group1' => '10.100.27.52',
>           'group2' => '10.100.27.53',
>           'group3' => '10.100.27.54',
>           'group4' => '10.100.27.55',
>           'group5' => '10.100.27.56',
>           'group6' => '10.100.27.57' #Last element has no comma...
> 
>         };
>        
> $count = 0;
> 
> while (($key, $value) = each %$VAR1) { # $key has group5 for intance,
> and $value its value.
> 
>    $count += 1;
> 
>    $output = "\<table$count\>\,$value\n";
>    print $output;
> 
> }
> 
> exit;
> 
> Cheers,
> 
> Miguel
> 
> Este e-mail foi enviado a partir de um computador sem vírus protegido
> pela Avast.
> www.avast.com <https://www.avast.com/sig-email>
> 
> 
> On Wed, Feb 17, 2016 at 11:15 AM, Vincent Lequertier <s...@riseup.net
> <mailto:s...@riseup.net>> wrote:
> 
>     Hello!
> 
> 
>     I have the following data(sanitized) :
> 
>     print Dumper \%vars
> 
>     $VAR1 = {
>               'group1' => '10.100.27.52',
>               'group2' => '10.100.27.53',
>               'group3' => '10.100.27.54',
>               'group4' => '10.100.27.55',
>               'group5' => '10.100.27.56',
>               'group6' => '10.100.27.57',
> 
>             };
> 
> 
>     print Dumper \@tables
> 
>     $VAR1 = [
>               {
>                 'tablename' => '<table1>',
>                 'ips' => [
>                            '"10.100.29.0/24 <http://10.100.29.0/24>"'
>                          ]
>               },
>               {
>                 'ips' => [
>                            '$group1',
>                            '$group2',
>                            '$group3'
>                          ],
>                 'tablename' => '<table2>'
>               },
>               {
>                 'tablename' => '<table3>',
>                 'ips' => [
>                            '$group4',
>                            '$group5'
>                            '$group6'
>                          ]
>               }
>             ];
> 
> 
>     How can I have the following output?
> 
>     <table1>,"10.100.29.0/24 <http://10.100.29.0/24>"
>     <table2>,10.100.27.52
>     <table2>,10.100.27.53
>     <table2>,10.100.27.54
>     <table3>,10.100.27.55
>     <table3>,10.100.27.56
>     <table3>,10.100.27.57
> 
>     Here is what I've tried:
> 
>     for my $table (@tables) {
>         foreach my $entry ($table->{ips}) {
>             print $table->{tablename};
>             print $vars{$entry};
>         }
>     }
> 
>     My problem is that I don't understand what I should use to loop over
>     'ips' and what to put inside $vars{}. Is my data structure appropriate
>     to my needs?
> 
>     Let me know If you need more information, if you need the full code, etc
> 
>     Thanks in advance
> 
> 
>     --
>     Vincent Lequertier
>     skysymbol.github.io <http://skysymbol.github.io>
> 
>     --
>     To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>     <mailto:beginners-unsubscr...@perl.org>
>     For additional commands, e-mail: beginners-h...@perl.org
>     <mailto:beginners-h...@perl.org>
>     http://learn.perl.org/
> 
> 
> 
> 
> 
> -- 
> /
> Rui Miguel Fernandes
> /
> /Porto - Portugal/
> 
> /Website:
> Cosmos - Portal Interactivo de Astronomia / Interactive Gate of Astronomy
> http://www.cosmos.pt/

-- 
Vincent Lequertier
skysymbol.github.io

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to