I have written a Perl script that would start a SNMP session and extracting the data/counters and it's value to a csv file. There are 7 perl scripts; different properties/definition/variables on the top.. but the engine is the same.

At this point, those 7 perl scripts are redundant except for the defined variables. Is there a way to keep the execution perl script as a properties/execution file and keep the engine in a another file? This properties/execution perl script will call the engine (using the properties defined in it's own script).

So in short, I want to use the variables in their own script (as an execution as well), but calls a specific function from a unified "engine".

i.e.

retrieve\_mibs1.pl retrieve\_mibs2.pl
retrieve\_mibs3.pl
retrieve\_mibs4.pl
retrieve\_mibs5.pl
retrieve\_mibs6.pl
retrieve\_mibs7.pl

retrieve\_mibs1.pl
------------------

```
#!/usr/local/bin/perl

use Net::SNMP;

##DEFINITION START

my @Servers = (
  'server1',
  'server2',
);

my $PORT = 161;

my $COMMUNITY = 'secret';

my $BASEOID = '1.2.3.4.5.6.7.8';

my $COUNTERS = [
  [11,'TotalIncomingFromPPH'],
  [12,'TotalFailedIncomingFromPPH'],
];

##ENGINE START
sub main {
  my $stamp = gmtime();
  my @oids = ();
  foreach my $counter (@$COUNTERS) {
    push @oids,("$BASEOID.$$counter[0].0");
  }
  foreach my $server (@Servers) {
    print "$stamp$SEPARATOR$server";
    my ($session,$error) = Net::SNMP->session(-version => 1,-hostname => $server,-port => $PORT,-community => $COMMUNITY);
    if ($session) {
      my $result = $session->get_request(-varbindlist => \@oids);
      if (defined $result) {
        foreach my $oid (@oids) {
          print $SEPARATOR,$result->{$oid};
        }
      } else {
        print STDERR "$stamp Request error: ",$session->error,"\n";
        print "$SEPARATOR-1" x scalar(@oids);
      }
    } else {
      print STDERR "$stamp Session error: $error\n";
      print "$SEPARATOR-1" x scalar(@oids);
    }
    print "\n";
  }
}
main();

```