Begin - Run arbitrary code before your script starts


Begin documentation Contained in the Begin distribution.

Index


Code Index:

NAME

Top

Begin - Run arbitrary code before your script starts

SYNOPSIS

Top

  perl -MBegin='print "hello world\n"' script.pl

  perl -MBegin='$debug = 1' script.pl

DESCRIPTION

Top

This module effectively allows to inject arbitrary code from the command line before running any perl script.

It can be used to set global variables.

I find it also useful when running the perl debugger as a REPL to test things. For instance:

  perl -MBegin='$ssh=Net::OpenSSH->new(host)' -de 1




SEE ALSO

Top

perlrun

COPYRIGHT AND LICENSE

Top


Begin documentation Contained in the Begin distribution.

package Begin;

our $VERSION = '0.01';

use strict;
use warnings;

use Data::Dumper;


sub import {
    package main;
    shift;
    eval "no strict; no warnings;\n" . join(',', @_);
    if ($@) {
	$@ =~ s/ at \(eval \d*\) line \d*//;
	warn "Begin error: $@";
	exit(1);
    }
}

1;
__END__