All pastes #438503 Raw Edit

cyrus

public text v1 · immutable
·published 2007-04-13 17:43 UTC
rendered paste body
sub parse_script {
   my $script = shift @_;
   my $section_name = '';
   my $in_section = 0;
   my $index = 0;
   
   print "reading in script file $script\n";
   open CONFIG, "< $script" or die "could not open script file\n";
   while (<CONFIG>) {
      if ($_ =~ m/(.*):start/ ) {
         $section_name = $1;
         $parsed_config{$1} = ();
         $in_section = 1;
      } elsif ($_ =~ m/(.*):end/ ) {
         $in_section = 0;
         $index = 0;
      } elsif ($in_section == 1) {
         $parsed_config{$section_name}[$index] = $_;
         $index++;
      }
   }
}

#--------------- user input -------------------------
print "enter the name of the script to run (blank to exit): ";
my $script = SCRIPT_LOCATION . <STDIN>;

print "enter the systems to run on (blank to exit): ";
my $sytems = SYSTEM_FILES_LOCATION . '/' . <STDIN>;

parse_script $script;
my $i;
for $i (keys %parsed_config) {
   print $parsed_config{$i};
   #foreach ($parsed_config[$i]) {
   #  print $_ . "\n";
   #}
}