in reply to Concatenating scripts intelligently

( For the reason I explained here, this node doesn't help the OP. This one does. )

Would the following do the trick?

# Info extracted from # <script onInit='use strict; my $x; my $y;' # onAwaken='print ++$x' # onAwaken='print ++$y'/> # my $onInit = 'use strict; my $x; my $y;'; my $onAwaken = 'print ++$x'; my $onSleep = 'print ++$y'; # Compile code my $code = "package Sandbox;" $code .= "$onInit;"; $code .= "sub onAwaken { $onAwaken }"; $code .= "sub onSleep { $onSleep }"; eval $code; # Dispatch an event Sandbox->onAwaken() if Sandbox->can('onAwaken');

The above can easily be expanded to handle multiple documents by generating incremental package names.

Replies are listed 'Best First'.
Re^2: Concatenating scripts intelligently
by diotalevi (Canon) on May 09, 2006 at 21:51 UTC

    That's very close to just having a separate "declare" section. The OP can do that too.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊