So I'm coding a simple backup restore utility and I get a bizarre error message:

   File '-4294967295' does not exist.

But after staring at the code for 10 minutes I still don't see how the filename is getting replaced with a number. Here's the relevent block:

my $file = shift @ARGV; die "Backup filename '$file' should end in .kba or .kba.gz.\n" unless $file =-~ /kba\.gz$/ or $file =~ /\.kba$/; die "File '$file' does not exist.\n" unless -e $file;

Then, at last, I see it - I'm using the =-~ operator rather than the =~ operator! Perl has taken my typo and turned it into an attempt to negate the bitwise inverse of the result of running a regex against $_. Sheesh!

-sam

Replies are listed 'Best First'.
Re: An Insane Typo Bug
by pg (Canon) on Nov 05, 2003 at 23:56 UTC

    The other possible output would be -4294967294. The result depends on whether m// returns 0 or 1.

    use strict; use warnings; my $file = "blah"; $_ = "kba.gz"; my $file =-~ /kba\.gz$/; print $file, "\n"; $_ = "abcd"; my $file =-~ /kba\.gz$/; print $file;
Re: An Insane Typo Bug
by Willard B. Trophy (Hermit) on Nov 07, 2003 at 20:18 UTC
    Sounds like something that a good Perl lint should query; a rare but valid operator. It doesn't seem that B::Lint can do this.

    It's a bit like a good spelling checker should alert you to the use of wether or pubic. Both are rare valid words, but common typos.

    --
    bowling trophy thieves, die!