187

Packages & Modules
BEGIN and END Blocks

  • You may define any number of code blocks named BEGIN and END which act as constructors and destructors respectively

      BEGIN { ... }
      END { ... }
      BEGIN { ... }
      END { ... }

  • Every BEGIN block is executed after the perl script is loaded and compiled but before any other statement is executed

  • Every END block is executed just before the perl interpreter exits


    Exercise
    1. Run the begin_end example script.
    2. Take a look at the script itself (click the "begin_end" icon).
    No
    Hint
    To
    Start

    begin_end

  • The BEGIN and END blocks are particularly useful when creating Perl modules...