[Setup-tool-hackers] Why my? and Re: package lister for xst




I'm doing the commit right now, with some corrections:

xst_xml_print_line already appends a new line at the end of the passed
string, so I trimed some \n's.

You should use 'my' instead of 'local' for local variables in Perl:
variables that use 'local' are still globals, which only receive temporary
values for the given scope. 'my' actually creates a new variable in the
given context environment, which is what we want to do, specially in
functions that return a ref to a 'my' var:

sub la { local $m; return \$m; }
sub lb { local $m; return \$m; }
sub ma { my $m; return \$m; }

la and lb always return the same value (the same reference), because $m is
a global, which was just receiving a temp value inside those functions. ma
always returns a diferent value, because every time we enter that
function, a new variable is created (and destroyed on its exit, if the
returned ref is not kept).

my is also faster, which may not be an issue, anyways.

Read man perlsub, section "Private Variables via my()" for further
reference.

Greetings,
Arturo



_______________________________________________
setup-tool-hackers maillist  -  setup-tool-hackers@ximian.com
http://lists.ximian.com/mailman/listinfo/setup-tool-hackers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]