Sorry, that was a last minute change.
In order to simplify the code for inclusion here, I left out a trivial optimization where I convert HASH to an integer:
use constant Array => 1;
use constant Hash => Array << 1;
our %_typemap=(ARRAY=>Array, HASH=>Hash);
sub _Var ($$$;$) { # Wrkhorse code for manu
+fctrd Vars
my ($__, $p, $vn, $wa)=@$_;
$_=$__; # must not trash '$_'
my $v = $p->{$vn}; # value
my $rfv = ref $v; # type(ref) of var
my $rfvi = $_typemap{$rfv} || 0;
my ($arg, $addrof);
if ($wa && $wa eq 'α') { $wa=undef, $addrof=1 }
if (@_ && !$addrof) { # arg for "setter"
$arg = shift;
my $refarg = ref $arg; # ref of the arg
unless ( defined($p->{$vn}) && defined $arg ){ # unless both de
+fined
$p->{$vn} = $arg;
} elsif ($rfvi == Array) { ## if type(var)==ARRAY,
+1 param
if ($refarg ne "ARRAY" || (@$arg || @$v)) {
push @{$p->{$vn}}, $_[0]; ## convert to "push"
}
} elsif ($rfvi == Hash) {
I tried to cut down the amount of code included by cutting out the integer thing...sorry. I didn't want to get dinged for not trying to cut things down...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|