in reply to read IPv4 addresses from array

You probably want something like the following (untested) code:

#!/usr/bin/perl use strict; use warnings; use Net::Appliance::Session; my @ipconadd = qw(1.1.1.1 2.2.2.2 3.3.3.3); doStuff($_) for @ipconadd; sub doStuff { my ($host) = @_; eval { my $session = Net::Appliance::Session->new( { personality => 'ios', transport => 'SSH', host => $host } ); $session->connect({username => 'admin', password => 'coolbro'} +); $session->begin_privileged({password => 'verycoolbro'}); print $session->cmd('show hostname'); print $session->cmd('show inventory | i SN'); $session->end_privileged; $session->close(); return 1; } or do { my $err = $@; warn "Failed to doStuff for '$host': $@\n"; }; }

Note the for loop over hosts that calls the sub to do stuff. The loop could be written long hand as:

for my $host (@ipconadd) { doStuff($host); }
Premature optimization is the root of all job security

Replies are listed 'Best First'.
Re^2: read IPv4 addresses from array
by andreyns (Initiate) on Aug 18, 2015 at 08:53 UTC
    I knew it! I could do that with "sub" section, but my programming skill too low. Thanks a lot! Your code working very good!