#!/usr/bin/perl our @fields; use mem(@fields=qw(one two three)); use Data::Vars \@fields, {one=>1, two=>2, three=>3}; use P; my $self=main->new(); P "one=%s, two=%s, three=%s", $self->one, $self->two, $self->three; #### > /tmp/t.pl one=1, two=2, three=3 #### > /tmp/t.pl Can't modify logical and (&&) in lvalue subroutine return at /Users/law.Bliss/bin/lib/Data/Vars.pm line 108, near "}" BEGIN not safe after errors--compilation aborted at /Users/law.Bliss/bin/lib/Data/Vars.pm line 111. Compilation failed in require at /tmp/t.pl line 4. BEGIN failed--compilation aborted at /tmp/t.pl line 4. #### sub _Var ($$$;$) :lvalue { # Wrkhorse code for manufctrd Vars my ($p, $vn, $wa) = @{(shift)}; # vn=varname my $c = ref $p || $p; my $rfv = ref $p->{$vn}; # rfv=ref(type) of var my $addrof; if ($wa && $wa eq 'α') { $wa=undef, $addrof=1 } my $arg = $_[0]; if (@_ && !$addrof) { # arg for "setter" my $rfa = ref $arg; # ref of the arg unless ( defined($p->{$vn}) && defined $arg ){ # if both not defined $p->{$vn} = $arg } elsif ($rfv eq ARRAY) { ## if type(var)==ARRAY, 1 param my ($index, $ap) = (shift, $p->{$vn}); if ($p->{':pusharray'} or ( !looks_like_number($index) || not( (defined $wa) || @_) )) { push @{$p->{$vn}}, ($index); ## convert to "push" return $index } ## return pushed value else { $p->{$vn}[$index] = $_[0] if @_; return $p->{$vn}[$index] if defined $wa } } elsif ($rfv eq HASH) { my $subvar = shift; ## 1 var w/hash is is a key $p->{$vn}{$subvar} = $_[0] if @_; ## another? =>assign value return $p->{$vn}{$subvar} if defined $wa } else { if ((length $rfv) && $rfv ne $rfa ) { ## incompat assignment warn P "Warning: var type redefined from \"%s\" to \"%s\"", $rfv, $rfa } $p->{$vn} = $_[0]; ## assignment is default return $p->{$vn} if defined $wa } } # how to return results? (below) if ($rfv eq ARRAY ) { if (defined($wa)) { # arrays special $wa? @{$p->{$vn}} : $addrof ? \$p->{$vn} : $p->{$vn} } } elsif ($rfv eq HASH ) { $p->{$vn} } elsif ($addrof) { return $p->{$vn} } else { return $p->{$vn} } } ## endsub (#108) # "address(ref)-of" function ( sub _addr_of_($) { (#111 -- basically next line of code) #### can't modify logical and (&&) in lvalue subroutine return. #### > perl -d bin/dedup Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. Can't modify logical and (&&) in lvalue subroutine return at /Users/law.Bliss/bin/lib/Data/Vars.pm line 108, near "}" BEGIN not safe after errors--compilation aborted at /Users/law.Bliss/bin/lib/Data/Vars.pm line 144. at /Users/law.Bliss/bin/lib/Data/Vars.pm line 144. require Data/Vars.pm called at bin/dedup line 21 main::BEGIN() called at /Users/law.Bliss/bin/lib/Data/Vars.pm line 144 eval {...} called at /Users/law.Bliss/bin/lib/Data/Vars.pm line 144 Compilation failed in require at bin/dedup line 21. at bin/dedup line 21. main::BEGIN() called at bin/dedup line 21 eval {...} called at bin/dedup line 21 BEGIN failed--compilation aborted at bin/dedup line 21. at bin/dedup line 21. Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<1> #### BEGIN { #140 if (require "Dbg.pm") { # import if there, else not; no error if not using TPe Dbg->import; } #143 } #144 #### use Data::Vars \@fields, {mmap=>1, aio_respQ=>{}, examine_paths=>[], SYS_IO=>1, use_child_ra=>1}; #### $a==NULL && $a=xxx; (needs parens or 'and' instead of '&&').