This line doesn't make any sense to me.for ( $sysDescr ) {
Giving the output some intend makes it easier to read when debugging nested loop/if situations. As long as you have no clue what is going wrong, up to one print in each loop or if block is a good thing. In many cases, the processing works, but the output isn't what you expect. Monitoring your $OutputLine variable may also be a good idea.foreach $hostName (@serverList) { print STDERR "--- Server: $hostName\n"; # snmpwalk as filehandle #---------------------------------- $FH_SNMPWALK = new FileHandle "$SNMPWALK $hostName $oidNbrSysDescr + 2>&1|"; die "$0: $! in Zeile: ", __LINE__ unless defined $FH_SNMPWALK; # execute snmpwalk #---------------------------------- while( $sysDescr = <$FH_SNMPWALK> ) { chomp $sysDescr; print STDERR " Desc: $sysDescr\n"; for ( $sysDescr ) { print STDERR " in_for: $_\n";
Besides of your probleme, you could shorten your code a little bit:
...or even shorter...if (s/$prefixSysDescr/$hostName$TAB/ or s/snmpwalk:\s*/$hostN +ame$TAB/) { $OutputLine = $_; last; }; # substitute some prefixes (this one works)
if (s/($prefixSysDescr|snmpwalk:\s*)/$hostName$TAB/) { $OutputLine = $_; last; }; # substitute some prefixes
In reply to Re: His strangeness regex
by Sewi
in thread His strangeness regex
by o_chfa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |