[Perl] Strange ne "NO" behavior.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Perl] Strange ne "NO" behavior.
# 1  
Old 05-22-2009
[Perl] Strange ne "NO" behavior.

Hi there,

I have a strange problem and I cannot figure it out what I am doing wrong here.
Let me try to picture it.
In principle it is prety straight forward, but something odd is happening.

Here is part of the input file snmp_alm.cfg:

Code:
##############################################################
# Specifies if the PURGE Notification should be sent or Not  #
# Yes means the PURGE Notification is Not sent (disabled)    #
# No viceversa                                               #
# Default Value is: NO                                       #
##############################################################

DISABLE_PURGE_NOTIF:           	YES


Here is part of the Perl code:

Code:
my $disable_purge_notif;
my $disable_purge_notif_value;

open (SNMP_ALM_CFG, $snmp_alm_cfg) or die "Cannot open $snmp_alm_cfg";
while (<SNMP_ALM_CFG>) {
  s/#.*//;            # ignore comments by erasing them
  next if /^(\s)*$/;  # skip blank lines
  s/^[\s\t]+//;       # remove leading tabs and spaces
  s/[\s\t]+$//;       # remove trailing tabs and spaces
  s/://;              # remove :
  chomp;
	
  @_=split(/[\s\t]+/, $_, 2); # split on tabs on spaces

if (/DISABLE_PURGE_NOTIF/) {
  $disable_purge_notif = $_[0];
  $disable_purge_notif_value = $_[1];
  printf "Found parameter    : $disable_purge_notif\n";
  printf "Current setting is : $disable_purge_notif_value\n";
  if ( $disable_ack_notif_value ne "NO" ) {
    printf "ERROR - Correct $disable_purge_notif setting is : NO\n";
  }
}  
}
close (SNMP_ALM_CFG);


This is the output when the parameter value is YES:

Code:
Found parameter    : DISABLE_PURGE_NOTIF
Current setting is : YES
ERROR - Correct DISABLE_PURGE_NOTIF setting is : NO

So far so good.
But now I set it to NO:

Code:
DISABLE_PURGE_NOTIF:           	NO

Now I get the following output:

Code:
Found parameter    : DISABLE_PURGE_NOTIF
Current setting is : NO
ERROR - Correct DISABLE_PURGE_NOTIF setting is : NO


I thought "NO" ne "NO" would give 0 or false.
Using the debugger I see that $disable_ack_notif_value is indeed 'NO', so I am confused here.

Anything I overlooked ?
# 2  
Old 05-22-2009
Might be that I'm overlooking something or that it's not part of the posted code, but where do you set $disable_ack_notif_value? I only see $disable_purge_notif and $disable_purge_notif_value.
# 3  
Old 05-22-2009
Quote:
Originally Posted by pludi
Might be that I'm overlooking something or that it's not part of the posted code, but where do you set $disable_ack_notif_value? I only see $disable_purge_notif and $disable_purge_notif_value.
Smilie

Stupid me. I already thought it had to be something like this. It made me crazy Smilie

This works:

Code:
if ( $disable_purge_notif_value ne "NO" ) {

Thanks !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. Shell Programming and Scripting

Weird behavior of command "local"

Hi there, I'm running into a very weird situation. Let's forget about the purpose of my initial script please. I noticed the bug whatever I'm trying to do. I'm on an old server running bash 3.1.17. Say we have the following script : foo:~# cat /tmp/test #!/bin/bash f1() { local... (9 Replies)
Discussion started by: chebarbudo
9 Replies

4. Programming

Strange "getsockopt" Solaris behavior

Please take a look on following code: s = socket(PF_INET, SOCK_STREAM, 0); //socket fcntl(s, F_SETFL, O_NONBLOCK); //set socket to nonblock retry_conn: ret = connect(s, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr_in)); // try to connect, for sure... (7 Replies)
Discussion started by: revolta25
7 Replies

5. Shell Programming and Scripting

Commenting out "expr" creates weird behavior

This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document <<EOF echo "Sum is: `expr $1 + $2`" EOF Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
Discussion started by: royalibrahim
3 Replies

6. UNIX for Advanced & Expert Users

Weird "sort" behavior

Hi, I'm trying to sort a text file "test": S12 S_S12 S_S1_12 S15 S_N15 S_N1_15 By "sort test", I get: S12 S15 S_N1_15 S_N15 S_S1_12 S_S12 It seems weird: Comparing Line 2 and Line 3, it must be that '-' is bigger than '1'; however, comparing Line 3 and Line 4, it seems that... (3 Replies)
Discussion started by: intermilan
3 Replies

7. UNIX for Advanced & Expert Users

"╭─ " Character combo in $PATH causes strange autocompletion behavior in zsh

I've posted about this before, but only recently narrowed the problem down to a specific cause. Ok, first of all, the behavior: It occurs when autocompletion brings up its list (not when there is only a single option). Basically, if I were to type, say, cd ~/<TAB> I would get something... (2 Replies)
Discussion started by: marshaul
2 Replies

8. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

9. Shell Programming and Scripting

"Odd" behavior exiting shell script

Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option? For example, if I have the example script (we'll name it ex.sh): #!/bin/sh if then echo "Bye." exit 2 fi And I execute it like this: >./ex.sh It... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question