Hi folks,

The documentation for the MAIN sub says that "the sub with the special name
MAIN is executed after all relevant phasers."

My understanding is that MAIN automatically executes before any code other
than phasers happening at compile time or at the end or right after the end
of compilation. It seems that this is not the case. It seems that my
perception is wrong and that code not belonging to any sub is executed
before MAIN.

For example, take this code:

sub execute_after_main(Str $string) {
    say "this $string after MAIN?";
}
execute_after_main("1");

sub MAIN() {
    say "This is MAIN so this should print first";
}
execute_after_main("2");

This prints the following:

this 1 after MAIN?
this 2 after MAIN?
This is MAIN so this should print first

I was expecting the MAIN message to be printed first.

Did I miss something? Is my understanding wrong? I'd never seen that, but I
guess all my scripts using MAIN had all the code in subs called from MAIN.
So maybe I've never hit that case.

Cheers,
Laurent.

Reply via email to