SHARE
TWEET

Untitled

a guest Apr 21st, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my @sites = ('a', 'b', 'c');
  7. my @servers = ('A', 'B');
  8. my @data_type = ("X", "Y", "Z");
  9.  
  10. foreach my $site (@sites) {
  11.     foreach my $server_type (@servers) {
  12.         foreach my $data (@data_type) {
  13.             #statements
  14.         }
  15.     }
  16. }
  17.    
  18. sub cartesian {
  19.     my @C = map { [ $_ ] } @{ shift @_ };
  20.     foreach (@_) {
  21.         my @A = @$_;
  22.         @C = map { my $n = $_; map { [ $n, @$_ ] } @C } @A;
  23.     }
  24.     return @C;
  25. }
  26.  
  27. my @sites = ('a', 'b', 'c');
  28. my @servers = ('A', 'B');
  29. my @data_type = ("X", "Y", "Z");
  30.  
  31. foreach (cartesian(@sites, @servers, @data_type)) {
  32.     ($data, $server_type, $site) = @$_;
  33.     print "$site $server_type $datan";
  34. }
  35.    
  36. use Set::CrossProduct;
  37.  
  38. my @sites = ('a', 'b', 'c');
  39. my @servers = ('A', 'B');
  40. my @data_type = ("X", "Y", "Z");
  41.  
  42. my $cross = Set::CrossProduct->new(
  43.     [ @sites, @servers, @data_type ]
  44.     );
  45.  
  46. while( my $tuple = $cross->get ) {
  47.     print "@$tuplen";
  48.     }
  49.    
  50. use strict;
  51. use warnings;
  52.  
  53. my %sites = (
  54.  
  55.     a => {
  56.         A => {
  57.             data_type => [ 'X', 'Y' ],
  58.         }
  59.     },
  60.  
  61.     b => {
  62.         B => {
  63.             data_type => [ 'Y', 'Z' ],
  64.         }
  65.     },
  66.  
  67.     c => {
  68.  
  69.     },
  70. );
  71.  
  72. for my $site ( keys %sites ) {
  73.     for my $server ( keys %{ $sites{ $site } } ) {
  74.         for my $data ( keys %{ $sites{ $site }{ $server } } ) {
  75.             my @data_types = @{ $sites{ $site }{ $server }{ data_type } };
  76.             say "On site $site is server $server with $data @data_types";
  77.         }
  78.     }
  79. }
  80.    
  81. while ( my ( $site, $site_info ) = each %sites ) {
  82.     while ( my ( $server, $server_info ) = each %{ $site_info } ) {
  83.         my @data_types = @{ $server_info->{data_type} };
  84.         say "On site $site we have server $server with data types @data_types"
  85.             if @data_types;
  86.     }
  87. }
  88.    
  89. for(my $i = 0; $i <= $#sites; $i++){
  90.     for(my $j = 0; $j <= $#servers; $j++){
  91.         for(my $k = 0; $k <= $#data_type; $k++){
  92.             do_functions ...
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top