in reply to Use of BEGIN block

cd /tmp mkdir fooa mkdir foob touch ./fooa/startlib.pl touch ./foob/startlib.pl touch ./foo.pl export RUNMETH='DEBUG'

In fooa/startlib.pl

#!/usr/bin/perl -w our $money = 10000; 1;

In foob/startlib.pl

#!/usr/bin/perl -w our $money = 20000; 1;

In foo.pl

#!/usr/bin/perl -w BEGIN { if ($ENV{'RUNMETH'} eq 'DEBUG'){ chdir qq~/tmp/working/fooa~; } else { chdir qq~/tmp/working/foob~; } } require qq~./startlib.pl~; print $money; 1;

Back in my day we had a development, a test, an acceptance, and various production instances. Code and configurations were all dependent on what you were working on. This was a useful way. Perhaps nowadays there is a superior method but, as you can see, this still works.

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: Use of BEGIN block
by ikegami (Patriarch) on Apr 28, 2025 at 11:20 UTC

    There's no point to using a BEGIN block in your program. It would behave the same without.