Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Looping through numerous snmp strings....

by jwkrahn (Monsignor)
on Sep 19, 2012 at 19:51 UTC ( #994512=note: print w/replies, xml ) Need Help??

in reply to Looping through numerous snmp strings....

open( RTR, "$rtrlist" ) || die "Can't open $rtrlist file"; ... open( LOG, ">$workingdir/RESULT.TXT" )|| die "Can't open $workingdir/R +ESULT.TXT file"; ... $rtr = `$snmpget . $snmpro[0] $rtr` or print "hos +tname failed: $!\n"; ... $rtr = `$snmpget . $snmpro[1] $rtr` or print +"Host not responding to $snmpro[1]\n";

Consistency is always good.    You should stick with either ( ... ) || ... or  ... or ...

The use of $! with backticks is wrong.    You SHOULD be using $! to indicate errors from open and $? to indicate errors from backticks.

printf " Router\t\t Location\t\t\tContact\t\t Serial\n"; printf LOG " Router\t\t; Location\t\t\t;Contact\t\t ;Serial\n";

You are using printf when you should be using print.

foreach (<RTR>) { chomp( $rtr = "$_" );

foreach needs to read the entire file into memory first before it can loop through the lines.    The usual, more efficient method is to use a while loop if you only need one line at a time.

Why are you copying the value in $_ to a string when it is already a string?

Replies are listed 'Best First'.
Re^2: Looping through numerous snmp strings....
by timmytimay (Initiate) on Sep 20, 2012 at 10:28 UTC

    Thanks Monks - some great advice! I'll give it a go and let you know if I have any more queries.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994512]
[marioroy]: Discipulus Hubris, that's not me :( :(, I do not know the reason, but was inspired years ago to do MCE. Back then made a promise that I would hang in there no matter the difficulties or hurdles along the way. This is the journey that is almost completed
[choroba]: software is never completed
[choroba]: becuase the hardware always changes beneath it, at least
[Discipulus]: yes i think I know a bit about you: if I would had the competence and the will to accomplish something like MCE.. i'd be running here and there with flags and t-shirt about.. ;=)
Lady_Aleena rolls over on the sofa, pulling a light blanket over her, and falls to sleep.
[Discipulus]: but world is fun beacause it is manifold

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-05-26 09:20 GMT
Find Nodes?
    Voting Booth?