Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thanks for a great forum. My problem was answered just by scrolling through previously solved problems. Great service!!..."

Geography

Where in the world do Tek-Tips members come from?

Bareword found where operator expected at errors

RFC1795 (IS/IT--Management)
24 Apr 12 6:03
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: http://fengnet.com/book/cisco.ios.cookbook.2nd/I_0596527225_CHP_2_SECT_19.html

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 blllttt

 
feherke (Programmer)
24 Apr 12 6:17
Hi

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

I think you should change it like this :

CODE --> Perl ( fragment )

@iftable=\Q$snmpwalk $rtr ifDescr\Q;
@iftable=qq{$snmpwalk $rtr ifDescr};

Feherke.
http://feherke.github.com/

RFC1795 (IS/IT--Management)
24 Apr 12 10:14
Thanks Feherke! Much appreciated .. no more errors.

No data either, but that's not a perl issue winky smile

 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close