in reply to Logical Not not working!!!

Some reading that might make this behavior more clear is Scalar values from perldata.

In order to have its ability to silently work with strings, numbers and booleans without explicit coding of intent, Perl actually stores appropriate values internally. When you use the expression $var = !$var;, you set the variable to FALSE and clear out any numbers or strings associated with it. When you then ask it to print $var, Perl checks what it knows about the value. Since you want a string and the value is FALSE, it outputs "", the false string. Hence, after toggling, you actually have @array = ('1', '', '1'); You can get your expected behavior if you numify, for example with the code $_ += 0 foreach @array;. This will tell Perl to store a numerical value, which it will check before output.

As a side note, you should pick visible characters as delimiters when checking what you are actually outputting. If you'd used print "<$_>"; for example, you would have gotten the much more obvious <1><><1> as output.

Replies are listed 'Best First'.
Re^2: Logical Not not working!!!
by baski (Novice) on Aug 20, 2010 at 21:46 UTC
    Thanks for a very clear explanation and advice about the log..I think its is a profound concept for a beginner..I am glad I asked