in reply to read IPv4 addresses from array

You can iterate over a list (or an array) using the foreach construct (see perlsyn):

foreach my $ip (@ipconadd) { print "Processing $ip:\n"; # ... print "IP $ip done.\n"; };

Replies are listed 'Best First'.
Re^2: read IPv4 addresses from array
by andreyns (Initiate) on Aug 18, 2015 at 09:00 UTC
    First of all. Thanks for the answer! I tried to use foreach construction, but get many syntax errors.

      If you want help with these "many syntax errors", you will have to show them to us.

        OMG! It is works! I had a problem like: Global symbol "$s" requires explicit package name at csc-getinfo.pl line 34. because last line was $s->close; Now I rewrite a little bit a script.
        #!/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); foreach my $ip (@ipconadd) { print "Processing $ip:\n"; my $s = Net::Appliance::Session->new({ personality => 'ios', transport => 'SSH', host => $ip }); eval { $s->connect({ username => 'login', password => 'password' }); $s->begin_privileged({ password => 'verycoolbro' }); print $s->cmd('show hostname'); print $s->cmd('show inventory | i SN'); $s->end_privileged; $s->close; }; print "IP $ip done.\n"; }; if ($@) { warn "failed to execute command: $@"; }