I've got a rookie question. I've been playing with it for a while today and can't get it to work. I'm trying to put together a script that matches a regex against a flat file that contains all our switches' names.

In the foreach loop, it prints off the expected results (the names that match $hostregex) and until I added the

my @version = $session->cmd('show version  ');

line, it appeared to go to the switch in question.

When I added

 my @version = $session->cmd('show version  ');

I get the following error:

myname@bast1:~/bin$ testloop 101a Global symbol "$session" requires explicit package name at /home/mynam +e/bin/testloop line 31. Execution of /home/myname/bin/testloop aborted due to compilation erro +rs. myname@bast1:~/bin$

Here's the script. Any help would really be appreciated.

#!/usr/bin/perl use Net::Telnet::Cisco ; use strict; #always and forever, amen. use warnings; #or else. use lib '/home/myname/bin/lib'; use subs ; if ($#ARGV != 0) { print "usage: enter the switchname \n"; exit; } my $hostregex = $ARGV[0] ; my $infile = "/home/myname/zen/zen_devices_out" ; # print "You're using: '$infile'\n\n" ; open INF , "$infile" or die $! ; my @lines = <INF> ; my @matches = (grep(/$hostregex/i,@lines)) ; foreach (@matches) { chomp($_) ; print "'$_'\n" ; my ( $p1 , $p2 ) = get_p() ; my $session = Net::Telnet::Cisco->new(Host => $_); $session->login('myname', $p1); if ($session->enable($p2) ) { } else { warn "Can't enable: + " . $session->errmsg; } } my @version = $session->cmd('show version '); print @version ; exit ;

In reply to Global symbol "$session" requires explicit package name by WearyTraveler

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.