<?xml version="1.0" encoding="windows-1252"?>
<node id="50802" title="Rhys" created="2001-01-09 22:05:52" updated="2004-09-15 18:06:21">
<type id="15">
user</type>
<author id="50802">
Rhys</author>
<data>
<field name="doctext">
&lt;h2&gt;Tutorial&lt;/h2&gt;
Check out the Net-SNMP Tutorial I wrote and tell me if there's anything hideous in it.  It's here:  [id://396223]
&lt;h2&gt;Latest Perl Conundrum&lt;/h2&gt;
Some of these are simple, some quite complex.  All of them are real problems I'm trying to solve for one reason or another.  (Usually, I'm trying to tighten code from N lines to N/5 lines.)
&lt;p&gt;
So here's the latest one.  In many of my applications using SNMP, I have to use the structure below over and over, almost verbatim.  The general structure is always the same, but certain parts - that I hope are clearly marked below - change to suit the particular task.  Anyway, here goes:
&lt;p&gt;
&lt;code&gt;
$mib = 'someMibObject';
$vb = new SNMP::Varbind([$mib]);
LOOP: while ( 1 ) {
  $var = $sess-&gt;getnext($vb);  # Get the next instance.
  if ( $sess-&gt;{ErrorNum} ) {
    # There was an error.  Print $sess-&gt;{ErrorStr}, then:
    last LOOP;
  }
  if ( $vb-&gt;tag ne $mib ) {
    # This happens when we've read past the end of this
    # MIB object.
    last LOOP;
  }
  # If we get here, we use $vb-&gt;iid or $var or both to do
  # something useful with the response.
}
&lt;/code&gt;
&lt;p&gt;
So the conundrum is whether or not there's a shorter way of doing this.  Perhaps with &lt;code&gt;$vb-&gt;tag eq $mib&lt;/code&gt; in the &lt;code&gt;while&lt;/code&gt; test, but that creates other issues.
&lt;p&gt;
Another way of doing this that is successful, but actually duplicates code (though is still a bit more succint and doesn't have the dreaded 'while 1') is like this:
&lt;p&gt;
&lt;code&gt;
$mib = 'someMibObject';
$vb = new SNMP::Varbind([$mib]);
# Note the duplicate getnext()'s...
LOOP: for ( $var = $sess-&gt;getnext($vb) ;
            ($vb-&gt;tag eq $mib) and (not $sess-&gt;{ErrorNum}) ; 
            $var = $sess-&gt;getnext($vb) )
{
  # If we get here, we use $vb-&gt;iid or $var or both to do
  # something useful with the response.
}
if ( $sess-&gt;{ErrorNum} ) {
  # There was an error.  Print $sess-&gt;{ErrorStr} and/or
  # croak() or whatever.
}
&lt;/code&gt;
&lt;p&gt;
Please /msg if you have any ideas.  If they're big, post to your scratchpad?  I'm mostly looking for style/efficiency opinions and insight, although if you come up with some genius method that eliminates four lines, I'll engrave your PM home node URL into the credits of all scripts that use your method.  :-)
&lt;p&gt;
&lt;h2&gt;General Stuff About Rhys&lt;/h2&gt;
Net admin, net security guy, sys admin, Perl hacker, jack of all trades.  Perl hacker means 'Perl hacker'.  I usually try to just figure it out rather than look it up.
&lt;P&gt;
Fortunately, that's just the code, not the algorithm.  Design once, code five or six times is the idea.  :-)
&lt;/P&gt;
&lt;P&gt;
I'm a &lt;A HREF="http://www.linux.org"&gt;Linux&lt;/A&gt; fan, a &lt;A HREF="http://www.usanetwork.com/series/thedeadzone/"&gt;Dead Zone&lt;/A&gt; fan, and hope &lt;A HREF="http://www.microsoft.com"&gt;these guys&lt;/A&gt; and &lt;A HREF="http://www.aol.com"&gt;these other guys&lt;/A&gt; are out of business by 2010.
&lt;/P&gt;
&lt;P&gt;
Oh, yeah.  I highly recommend &lt;A HREF="http://www.islamic-knowledge.com/"&gt;this&lt;/A&gt; to anybody still looking, although you can't put too much faith in a Web site on the topic.  Like anything else, there's a lot of (ahem) discussion on most of the more interesting topics.  All I can say is there's way too much arguing.
&lt;/P&gt;
&lt;P&gt;
And it's often worth watching &lt;A HREF="http://www.ugcs.caltech.edu/st-tng/"&gt;these&lt;/A&gt;, if only because every now and then, you learn something about yourself.
&lt;/P&gt;
&lt;P&gt;
By the way, I'm boycotting any store that already has freakin' Christmas decorations up.  (Posted 11/3/2003.)  That includes &lt;A HREF="http://www.target.com"&gt;Target&lt;/A&gt; and &lt;A HREF="http://www.jcpenney.com"&gt;JC Penney&lt;/A&gt;.  Starting early is how the accountants boost their 'Christmas Sales' figures.  It's all crap, so I'm not playing.
&lt;p&gt;
&lt;h2&gt;Picture Explanation&lt;/h2&gt;
&lt;p&gt;
This &lt;i&gt;fat&lt;/i&gt; cat is Josephine ('Jo the Cat').  We don't really know much about Jo, except that she's a typical, sorta-neurotic, very opinionated female cat.  I picked her up in the [http://iccm.missouri.org|mosque] parking lot one day last January and have been taking care of her ever since.
&lt;p&gt;
Jo likes fighting with Snowplow (picture pending), waking everyone up at 4:00am, and generally forcing her way onto my lap.  Laptops, books, food, etc. are not obstacles.  I'm convinced she has created and fixed several Perl bugs with her keyboard dancing.
&lt;p&gt;
The picture above is Jo in full catness: napping in the warm spot on the carpet on a cold Missouri March afternoon.  What's amazing is that she wasn't in the laundry basket off to the bottom right...
&lt;p&gt;
&lt;h2&gt;Nodes I Think Are Handy&lt;/h2&gt;
&lt;p&gt;
Hundreds of monks have 'handy nodes' sections!  This is one of them!
&lt;p&gt;
[id://391416]&lt;br&gt;
[id://392124]&lt;br&gt;
[id://389028]&lt;br&gt;
[id://392350]&lt;br&gt;
[borg's belly] (point and stare)&lt;br&gt;
[id://236827]&lt;br&gt;
[id://8874]&lt;br&gt;
[id://386413]&lt;br&gt;</field>
<field name="lasttime">
2010-12-28 12:07:39</field>
<field name="experience">
765</field>
<field name="user_scratchpad">
388824</field>
<field name="imgsrc">
392208</field>
<field name="timeformat">
</field>
<field name="numwriteups">
72</field>
<field name="location">
Columbia, MO</field>
<field name="timezone">
America/Chicago</field>
<field name="codewrapoff">
</field>
<field name="codewraplength">
</field>
<field name="codeautowrap">
</field>
<field name="codeprefix">
</field>
<field name="codebig">
</field>
</data>
</node>
