Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bareword found where operator expected at errors

Status
Not open for further replies.

RFC1795

IS-IT--Management
Feb 13, 2003
76
US
Hi All

I'm trying to get a perl script to work that I found in a Cisco Cookbook. My knowledge of perl is very limited so I'm not sure what the issue is and digging around the net is not helping me much.

The script from:
Code:
#!/usr/bin/perl
#
#           rt.pl -- a script to extract the routing table
#                    from a router.
#
#Set behavior
$snmpro="public";
#
$x=0;
$snmpwalk="/usr/bin/snmpwalk -v 1 -c $snmpro";
$snmpget="/usr/bin/snmpget -v 1 -c $snmpro";
chomp ($rtr=$ARGV[0]);
if ( $rtr eq "" ) {die "$0: Must specify a router\n"};
print "Destination\tMask\t\tNexthop";
print "\t\t Proto\tInterface\n";
@iftable=\Q$snmpwalk $rtr ifDescr\Q;
for $ifnum (@iftable) {
    chomp (($intno, $intname) = split (/ = /, $ifnum));
    $intno=~s/.*ifDescr\.//;
    $intname=~s/"//gi;
    $int{$intno}=$intname;
}
@ipRouteDest=\Q$snmpwalk $rtr ipRouteDest\Q;
@ipRouteMask=\Q$snmpwalk $rtr ipRouteMask\Q;
@ipRouteNextHop=\Q$snmpwalk $rtr ipRouteNextHop\Q;
@ipRouteProto=\Q$snmpwalk $rtr ipRouteProto\Q;
@ipRouteIfIndex=\Q$snmpwalk $rtr ipRouteIfIndex\Q;
#@ipRouteMetric1=\Q$snmpwalk $rtr ipRouteMetric1\Q;
for $intnum (@ipRouteIfIndex) {
    chomp (($foo, $int) = split (/= /, $intnum));
    chomp (($foo, $dest) = split (/: /, @ipRouteDest[$x]));
    chomp (($foo, $mask) = split (/: /, @ipRouteMask[$x]));
    chomp (($foo, $nhop) = split (/: /, @ipRouteNextHop[$x]));
    chomp (($foo, $prot) = split (/= /, @ipRouteProto[$x]));
    #chomp (($foo, $metr) = split (/= /, @ipRouteMetric1[$x]));
    $int1 = $int{$int};
    if ($int1 eq '') {$int1="Local"};
    $prot=~s/\(.*//; $prot=~s/ciscoIgrp/\(e\)igrp/;
    printf ("%-15s %-15s %-15s %7s %-25s\n",$dest, $mask, $nhop, $prot, $int1);
    $x++
}
Gives me the following errors:
Code:
Bareword found where operator expected at ./rt.pl line 16, near "$rtr ifDescr"
        (Missing operator before ifDescr?)
Backslash found where operator expected at ./rt.pl line 16, near "ifDescr\"
Bareword found where operator expected at ./rt.pl line 23, near "$rtr ipRouteDest"
        (Missing operator before ipRouteDest?)
Backslash found where operator expected at ./rt.pl line 23, near "ipRouteDest\"
Bareword found where operator expected at ./rt.pl line 24, near "$rtr ipRouteMask"
        (Missing operator before ipRouteMask?)
Backslash found where operator expected at ./rt.pl line 24, near "ipRouteMask\"
Bareword found where operator expected at ./rt.pl line 25, near "$rtr ipRouteNextHop"
        (Missing operator before ipRouteNextHop?)
Backslash found where operator expected at ./rt.pl line 25, near "ipRouteNextHop\"
Bareword found where operator expected at ./rt.pl line 26, near "$rtr ipRouteProto"
        (Missing operator before ipRouteProto?)
Backslash found where operator expected at ./rt.pl line 26, near "ipRouteProto\"
Bareword found where operator expected at ./rt.pl line 27, near "$rtr ipRouteIfIndex"
        (Missing operator before ipRouteIfIndex?)
Backslash found where operator expected at ./rt.pl line 27, near "ipRouteIfIndex\"
syntax error at ./rt.pl line 16, near "$rtr ifDescr"
syntax error at ./rt.pl line 23, near "$rtr ipRouteDest"
syntax error at ./rt.pl line 24, near "$rtr ipRouteMask"
syntax error at ./rt.pl line 25, near "$rtr ipRouteNextHop"
syntax error at ./rt.pl line 26, near "$rtr ipRouteProto"
syntax error at ./rt.pl line 27, near "$rtr ipRouteIfIndex"
Execution of ./rt.pl aborted due to compilation errors.

Anyone notice any blatant errors in that? I'd expect a script in a printed book to work as is :p
 
Hi

Seem you thoroughly misunderstood the meaning of [tt]\Q[/tt]. See Quoting metacharacters in [tt]man perlre[/tt] vs. Quote and Quote-like Operators in [tt]man perlop[/tt].

I think you should change it like this :
Code:
[s][navy]@iftable[/navy][teal]=\[/teal]Q[navy]$snmpwalk[/navy] [navy]$rtr[/navy] ifDescr[teal]\[/teal]Q[teal];[/teal][/s]
[navy]@iftable[/navy][teal]=[/teal][b]qq[/b][green][i]{$snmpwalk $rtr ifDescr}[/i][/green][teal];[/teal]

Feherke.
 
Thanks Feherke! Much appreciated .. no more errors.

No data either, but that's not a perl issue ;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top