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>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
On Wed, Feb 17, 2016 at 11:15 AM, Vincent Lequertier <[email protected]> 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"'
> ]
> },
> {
> '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"
> <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
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
--
*Rui Miguel Fernandes*
*Porto - Portugal*
*Website: Cosmos - Portal Interactivo de Astronomia / Interactive Gate of
Astronomyhttp://www.cosmos.pt <http://www.cosmos.pt>*