Hi all, I've a problem with a script done by myself that I need to transform in a parametrical solution. My scrypt interact with an ADABAS db launching command to manage fields. Originally I wrote a static solution that work but it's not my target. In ADABAS fields are ohisically named as 2 char ( AA,AB,DC,DE etc.). This scripts extract from a shell command a sorted fields list of a $file in a $Database given from user, then finds the next available field.

use strict; my $file = ""; my $Database = ""; print "Inserire il Numero del file da analizzare: "; $file = <>; chomp $file; print "\n"; print "Inserire il Numero del Database su quale si vuole fare l'analis +i: "; $Database = <>; chomp $Database; print "\n"; my $cmd1 = "adarep db=$Database fdt file=$file "; my @ElencoDati = `$cmd1 |grep " 1 I "`; push (@ElencoDati, `$cmd1 |grep "SUPER"`); my $ClearScr = `clear`; my @array1 = ""; my @ElencoCampi = ""; foreach (@ElencoDati) { @array1 = split /\s+/, $_; push (@ElencoCampi, $array1[3]); } my @ElencoCampiOrdinati = sort @ElencoCampi; # SORTED ARRAY OF FIELDS print "\n Elenco Campi Assegnati sul file $file del DB $Database Ordin +ati \n"; foreach (@ElencoCampiOrdinati) { print "$_\n"; } print "\nL'ultimo campo utilizzato sul file $file del database $Databa +se e: ", $ElencoCampiOrdinati[$#ElencoCampiOrdinati],"\n\n\n"; my $UltimoCampo = $ElencoCampiOrdinati[$#ElencoCampiOrdinati]; chomp $UltimoCampo; my @Caratteri = split (//,$UltimoCampo); print "\n"; my $PrimaLettera = ord $Caratteri[0]; print "Il valore numerico nella tabella ASCII della prima lettera e: $ +PrimaLettera\n\n"; my $SecondaLettera = ord $Caratteri[1]; print "Il valore numerico nella tabella ASCII della seconda lettera e: + $SecondaLettera\n\n"; if ( $SecondaLettera < 90 ) { $SecondaLettera+=1; my $ProssimoCampo = chr ($PrimaLettera).chr($SecondaLettera); print "\n\nIl prossimo campo disponibile e: $ProssimoCampo\n\n"; # THI +S IS NEXT AVAILABLE FIELD } if ( $SecondaLettera == 90 ) { $PrimaLettera+=1; $SecondaLettera=65; my $ProssimoCampo = chr ($PrimaLettera).chr($SecondaLettera); print "\n\nIl prossimo campo disponibile e: $ProssimoCampo\n\n"; } #END

PROBLEM GOING ON NEXT STEP I need to automatically define the environment taken from server hostname and generate automatically the same result for any $Database of the server for a user given $file. so I've established the environment:

my $hostname = `hostname`; my $Environment; my @Databases; my $AdabasScriptDir; my $AdabasProductionScript; if ( $hostname =~ /itrmsl12/ ) { $Environment = "SVILUPPO"; @Databases = ("5","6"); $AdabasScriptDir = "/opt/app1vg/appl/script/Utility/sag/adabas/"; } if ( $hostname =~ /itrmcl01/ ) { $Environment = "COLLAUDO"; @Databases = ("2","27","37"); $AdabasScriptDir = "/opt/app1vg/appl/script/Utility/sag/adabas/"; }

...now I would like to make a sub(@Databases) that give a separate Array of result... the question is in which way? My idea is to obtain something like:

%Databases ( "2" => (@ElencoCampiOrdinati), ($ProssimoCampo) "27" => (@ElencoCampiOrdinati), ($ProssimoCampo) "37" => (@ElencoCampiOrdinati), ($ProssimoCampo) )

...could someone explain to me how could I proceed?


In reply to Hash of Arrays or Arrays of arrays? and how proceed? by paride

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.