This is a prime example of why I preach so heavily about use strict;. If you had invoked that pragma you'd have seen the warning:
Quoting from Gabor Szabo on his website http://perl5maven.com/the-default-variable-of-perl:Use of uninitialized value $_ in print at sopw-simple.pl line 6.
In Perl, several functions and operators use this variable as a default, in case no parameter is explicitly used. In general, I'd say you should NOT see $_ in real code. I think the whole point of $_ is that you don't have to write it explicitly. Well, except when you do. Having a default variable is a very powerful idea, but using it incorrectly can reduce the readability of your code.Just for grins I tried:
and Perl was not happy with that issuing:$_ = "TestA" or "TestB";
Found = in conditional, should be == at ./sopw-simple.pl line 4. Useless use of a constant (TestB) in void context at ./sopw-simple.pl +line 4. TestA
My suggestion is read the web page I provided above for some hints on what you can and can't do with $_. Just a thought...
In reply to Re: Implicit assignment to $_
by blue_cowdawg
in thread Implicit assignment to $_
by SimplySimple
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |