in reply to Implicit assignment to $_
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Implicit assignment to $_
by tobyink (Canon) on Feb 26, 2013 at 17:01 UTC | |
by blue_cowdawg (Monsignor) on Feb 26, 2013 at 18:40 UTC | |
by tobyink (Canon) on Feb 26, 2013 at 20:21 UTC | |
by hippo (Archbishop) on Feb 26, 2013 at 22:40 UTC | |
|
Re^2: Implicit assignment to $_
by McA (Priest) on Feb 26, 2013 at 16:19 UTC |