Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Hopefully it wasn't my slides [] that were way off ;-) Here's how I poked at the internals of a program, including global variables. I got the idea from another post here on use Perl, and I hacked out this working program and test.

    phred@pooky ~ $ cat
    #!perl -w

    use strict;
    use warnings;

    our $var = 0;

    sub addition {
        my ($one, $other_one) = @_;
        my $result = $one + $other_one+$var;
        return $result;

    sub should_die {
        die "oops";


    phred@pooky ~ $ cat foo.t

    use strict;
    use warnings FATAL => 'all';

    use Test::More tests => 3;

    my $class = 'program';
    import $class qw( addition should_die);

    no strict 'refs';
    ${"main\:\:var"} = 5;
    my $method = 'addition';
    cmp_ok($method->(1,1), '==', 7, '1+1+var returns 7');

    $method = 'should_die';
    eval { $method->() };
    like($@, qr/oops/i, 'should_die() died');
    • Oops, I forgot the output

      phred@pooky ~ $ perl foo.t
      ok 1 - require '';
      ok 2 - 1+1+var returns 7
      ok 3 - should_die() died