Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: override keywords "my" and "our"

by jeremygwa (Initiate)
on Mar 18, 2009 at 00:14 UTC ( [id://751318]=note: print w/replies, xml ) Need Help??


in reply to Re: override keywords "my" and "our"
in thread override keywords "my" and "our"


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

Replies are listed 'Best First'.
Re^3: override keywords "my" and "our"
by GrandFather (Saint) on Mar 18, 2009 at 02:55 UTC

    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
Re^3: override keywords "my" and "our"
by ww (Archbishop) on Mar 18, 2009 at 00:59 UTC

    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.

Re^3: override keywords "my" and "our"
by ikegami (Patriarch) on Mar 18, 2009 at 01:00 UTC
    Unless that value happens to be undef for scalars and empty for array and hashes, you're out of luck.
Re^3: override keywords "my" and "our"
by rcaputo (Chaplain) on Mar 19, 2009 at 15:41 UTC

    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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://751318]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found