in reply to Really dumb question... ('ne' not working)
This works for me under WIN32 and linux, perl 5.6.0. C:\>type test.pl #!/usr/bin/perl use strict; use warnings; use diagnostics; open (OUTPUTFILE, ">./file.txt") || die "Oops $!"; my $tmp_dir = "foo"; my $dir = "bar"; if ($tmp_dir ne $dir) { print OUTPUTFILE "\n" . $tmp_dir . "\n"; $dir = $tmp_dir; } close OUTPUTFILE; C:\>perl test.pl C:\>type file.txt foo C:\> The only way I could reproduce the error you describe is to do this (ie put in a != in place of ne): C:\>type test.pl #!/usr/bin/perl use strict; use warnings; use diagnostics; open (OUTPUTFILE, ">./file.txt") || die "Oops $!"; my $tmp_dir = "foo"; my $dir = "bar"; if ($tmp_dir != $dir) { print OUTPUTFILE "\n" . $tmp_dir . "\n"; $dir = $tmp_dir; } close OUTPUTFILE; C:\>perl test.pl Argument "foo" isn't numeric in numeric ne (!=) at test.pl line 11 (#1 +) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the message will identify which operator was so unfortunate. C:\> If you genuinely have ne I suspect your perl may be broken!! If you have ne in the above code perl is quite happy even if both the vars *are actually numeric* vis: C:\>type test.pl #!/usr/bin/perl use strict; use warnings; use diagnostics; open (OUTPUTFILE, ">./file.txt") || die "Oops $!"; my $tmp_dir = 2; my $dir = 1; if ($tmp_dir ne $dir) { print OUTPUTFILE "\n" . $tmp_dir . "\n"; $dir = $tmp_dir; } close OUTPUTFILE; C:\>perl test.pl C:\> Note that this runs quite happily. Perl stringifies the numeric values in $tmp_dir and $dir for ne to use. Because the behavior you describe is not repeatable, and should not logically occur as perl should be automatically stringifying the values in $tmp_dir and $dir if required I suggest you may have a corrupt perl binary. It does happen. I agree that use strict; use warnings; and use diagnostics; may help. Unfortunately if you have a big script that was not written under use strict you will have a lot of tweaking to do yo get it to run (mostly declaring your variables with my), but other stuff too. Good luck Suggest testing on another box to test dud perl hypothesis tachyon
|
|---|