in reply to override keywords "my" and "our"

You can't from pure Perl - my and our are keywords, not functions, so they cannot be overridden.

You may be able to archieve what you want (but since you don't say what you want, it remains a guess) by using an appropriate B:: module and muck around in the opcode tree.

Replies are listed 'Best First'.
Re^2: override keywords "my" and "our"
by jeremygwa (Initiate) on Mar 18, 2009 at 00:14 UTC

    basically, I would like to initialize all variables to a certain value.
    hopes this helps you understand. thanks in advance.
    -Jeremy

      You would be better to always use strictures (use strict; use warnings;) and fix each error or warning by understanding why it is being generated and fixing the root cause rather than applying band aids to patch over the issue. Maybe you could tell us what the real issue is?


      True laziness is hard work

      so...

      my $foo = 3; my $bar = "keyword mania"; my @blivitz = "(some set of value);

      within code blocks, subs, or suchlike, when you need them ...and only when you need them.

      For example:

      my $bar = "keyword mania"; ... (do something); ... (and something more); bax($bar); # send $bar to sub bax for further proce +ssing ...(more code) { # bare block my @blivitz = ("7", '144', '1.16', "bat",); # @blivitz values availab +le only in this block ... do something with the elements of @blivitz; } # end block sub bax { # and here's the sub, bax my $foo = "3"; ...do something to the value in $bar (a global) with $foo (availab +le only in the sub); return (something); }

      Make sure you understand scoping and the issues created by making your variables global.

      Unless that value happens to be undef for scalars and empty for array and hashes, you're out of luck.

      For lexical variables, you may be able to do something with Lexical::Persistence.

      #!perl use warnings; use strict; use Lexical::Persistence; # Create a new dynamic closure. my $dc = Lexical::Persistence->new(); # Prime a variable with a value. $dc->set_context( _ => { '$cat' => "persistent" } ); # Call a function within it. $dc->call(\&function); exit; sub function { # $cat is already initialized. print "persistent cat is '", my($cat), "'\n"; }