in reply to Can I Force perl to Check Subroutine References at Compile Time?

I think you're finding that Perl ignores the if statement as it can never be true. When you try another combination that at least has some hope of being true, Perl will report the error:
my $foo = 1; if ($foo eq "1") { print hello(); } sub helloBROKEN { print "hello world\n"; }

Update: The question said compile time - doh! - thanks eg, I need to pay more attention!

Update 2: Thanks spaz! I admit I didn't deparse it so it's nice to see the confirmation.

--
I'd like to be able to assign to an luser

  • Comment on Re: Can I Force perl to Check Subroutine References at Compile Time?
  • Download Code

Replies are listed 'Best First'.
Deparse to the rescue!
by spaz (Pilgrim) on Jan 26, 2001 at 03:55 UTC
    cat >> test.pl #!/usr/bin/perl -w use strict; if( "1" eq "2" ) { print hello(); } sub helloBROKEN { print "Hello world\n"; } ---------------------------------- > perl -MO=Deparse test.pl test.pl syntax OK '???'; sub helloBROKEN { print "Hello world\n"; }
    You're exactly right about perl not even looking at that if statement.
Re: Re: Can I Force perl to Check Subroutine References at Compile Time?
by eg (Friar) on Jan 26, 2001 at 00:08 UTC

    This compiles fine (run it under perl -c.) If you want to get a compile-time error rather than a run-time error, you need to do what tye says below.