I have some code that handles 'variables' in a class's "hash". Various reasons for it, but main that I remember (it's been around for a few years), was to prevent me from accidently putting in 'garbage' in the {} when I accessed a class var. In line with that, the Data::Vars class does various types of complaining, some of which can be silenced, but will complain about trying to access a var not in the class (or initialize a var not in the class), can complain if you already have an accessor for the 'var', can set it up to perform "default initializations", for the vars that get set on any new object, if a ref, can make sure the "type" isn't changed at runtime, by accident (i.e. a warning). among a few other things. They get used a fair amount in much of the code I write. An example from code running against 5.16:
#!/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;
running it produces no big surprises:
> /tmp/t.pl one=1, two=2, three=3
Where my surprise has come is trying to run in under 5.14 on cygwin. I get an immediate error:
> /tmp/t.pl Can't modify logical and (&&) in lvalue subroutine return at /Users/la +w.Bliss/bin/lib/Data/Vars.pm line 108, near "}" BEGIN not safe after errors--compilation aborted at /Users/law.Bliss/b +in/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.
This has me stumped, since the line it is pointing to just has the "}" on the line (it closes a routine I call the 'main workhorse' of the class). Additionally, in that routine, there ARE no uses of '&&'. While the Vars.pm module has other code in it, this work horse routine is relatively short at 44 lines:
sub _Var ($$$;$) :lvalue { # Wrkhorse code for manu +fctrd 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 de +fined $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 val +ue 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)
The line with the 'endsub' is line #108 -- the line with the message that says:
can't modify logical and (&&) in lvalue subroutine return.
in it.

Not very helpful. Trying to run it under the debugger, I get a bit more information:

> 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/la +w.Bliss/bin/lib/Data/Vars.pm line 108, near "}" BEGIN not safe after errors--compilation aborted at /Users/law.Bliss/b +in/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 lin +e 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>
I.e. The problem might be closer to 144? What is there?...
BEGIN { #140 if (require "Dbg.pm") { # import if there, else not; no error if + not using TPe Dbg->import; } #143 } #144
...Another closing brace and no '&&' in sight. That is called from line 21 in dedup:
use Data::Vars \@fields, {mmap=>1, aio_respQ=>{}, examine_paths=>[], S +YS_IO=>1, use_child_ra=>1};
...This would seem to be a normal line to define & init vars in that module. Still no sign of logical 'AND'.

....Hmmm... I'm stumped. If anyone knows the secret code behind the above encrypted error message... and could explain what I should be looking for to fix, (or what I should fix), would appreciate it. I' be happy to post the rest of Data::Vars (~400 lines total), if people think that would be useful.

Anyone seen this type of error before...? The closest I can think of is when I have tried something like:

$a==NULL && $a=xxx; (needs parens or 'and' instead of '&&').
But don't see anything resembling that in the above or the rest of the code.

Ideas?


In reply to weird error message in middle-aged-perl(5.14) by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.