newbie syntax question

Austin Schutz tex at
Tue Apr 10 12:44:22 CDT 2001

On Tue, Apr 10, 2001 at 11:59:50AM -0500, Roth, Gabrielle wrote:
> I'm maintaining a script written by my predecessor.
> Here's the relevant snippet with line numbers:
>     21  if (open (HINFO, "$snmpget '$router' '$community' '$oid' 2>/dev/null
> |")) {
>     22    while (<HINFO>)
>     23      {
> 			<snip fun parsing stuff>
>     31        }
>     32      }
>     33    close HINFO;
>     34  } else {
>     35    die "failed to run $snmpget";
>     36  }
> I have two questions, both regarding line 21:
> 1 - (probably more of a unix question) the redirection to /dev/null:  I know
> this isn't the output of the command, because that's available via <INFO>
> for the parsing loop.  So what is this for?  Is it dumping the exit status?

	It's for ignoring STDERR of the snmpget process.

> Is it necessary?  It works without it, but I'm wondering if it's some error
> handling thing that I can't test and won't know if it's broken until it
> breaks. :)

	That's basically true, you won't know why snmpget failed if/when it
does. The parsing routine should tell you you don't have any useful
output but it can't tell you why.

> 2 - what is the pipe for at the end of the command?  I've tried it without
> this and I get this error:
> failed to run /usr/bin/snmpget at ./mrtg-cpustate line 35.
> Thanks for any pointers/insight!
	This is a very basic question. You should pick up a copy of
_Learning Perl_ or a similar book.
	Until then you should be able to do perldoc -f open on your
machine, which has an explanation of "|" at the end of the string
passed to open.


More information about the Pdx-pm-list mailing list