in reply to His strangeness regex
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: His strangeness regex
by o_chfa (Acolyte) on Sep 04, 2009 at 08:10 UTC | |
by Anonymous Monk on Sep 04, 2009 at 08:41 UTC | |
by o_chfa (Acolyte) on Sep 04, 2009 at 09:44 UTC | |
by Anonymous Monk on Sep 04, 2009 at 10:04 UTC | |
by o_chfa (Acolyte) on Sep 04, 2009 at 10:32 UTC | |
| |
by biohisham (Priest) on Sep 04, 2009 at 11:05 UTC |