Hmm, this might be a way to make it more convienant.
#!/usr/bin/perl -w
package Namespace;
use strict;
# bless the namespace into our module
sub new
{
my($class, $pkgname) = @_;
bless \$pkgname, ref($class) || $class;
}
# wrap some code into our namespace
sub do
{
my($self) = shift;
my $code = join "", @_;
eval qq{
package $$self;
$code;
};
if($@) {
print "eval failed: $@\n";
}
}
1;
package main;
my $n = new Namespace("foo");
$n->do(
q{
$a = 666;
print "$a\n";
print "a lot of stuff.\n";
}
);
This way, you could wrap large chunks of code with q{}
and not have to worry about escaping characters.
|