That shows that trying to retype code to simplify it shouldnt be done after 2am. This time I am pasting the code as it is.
#!/usr/bin/perl -w use strict; use Net::SNMP; my @devices = qw(2500 7200 7500 12000); my $retries = "1"; my $wait = "5.0"; my $mtu = "1500"; my $version = "1"; my $debug = "0"; my $community = "public"; my $snmp_username = ""; ## v3 my $snmp_authkey = ""; ## v3 my $snmp_authpassword = ""; ## v3 my $snmp_authprotocol = ""; ## v3 my %oid = ( version => ".1.3.6.1.2.1.1.1.0", ); &execute("run","tftp"); sub execute { ## pull source and destination of files my %args = ( s => $_[0], d => $_[1], ); foreach (@devices) { chomp $_; $args{h} = $_; &action(\%args); } } sub action { my $args = shift; ## set up initial parameters for this nodes snmp session(s) my $s = &create_snmp($args); ## grab the ios major revision number my $ios_version = $s->get_request ($oid{version}); ## grab an error if it exists $args->{e} = $s->error; ## close the snmp session $s->close; print "$args->{h} has IOS:\n\n$ios_version\n\n"; } sub create_snmp { ## get hostname to be used into local variable my $args = shift; ## create the hash of version independent options to pass to the met +hod my %snmp_options = ( hostname => "$args->{h}", retries => "$retries", timeout => "$wait", mtu => "$mtu", version => "$snmp_version", debug => "$debug", ); ## declare our variable to be set and returned my $s; ## test for snmpv3 usage if ( $snmp_version eq "snmpv3" ) { $snmp_options{username} = "$snmp_username"; $snmp_options{authkey} = "$snmp_authkey" if ($snmp_authkey); $snmp_options{authpassword} = "$snmp_authpassword" if ($snmp_authpassword); if ($snmp_authprotocol) { $snmp_options{authprotocol} = "$snmp_authprotocol"; $snmp_options{privkey} = "$snmp_authkey"; $snmp_options{privpassword} = "$snmp_authpassword"; } ## initiate session with v3 values $s = Net::SNMP->session(\%snmp_options); } else { ## set the v1/2c specific session traits $snmp_options{community} = $community; ## initiate session with v1/2c values $s= Net::SNMP->session(\%snmp_options); } ## provide our new session information return $s; ## end create_snmp() }

Thanks for looking into this. -c


In reply to Re: Re: using return to create a module object by c
in thread using return to create a module object by c

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.