That's were I was going (where I wanted to end up) as I was trying to remove the duplication in the code. The 2 mentions of the L-value "$pkg->{DIST} were definite candidates for reduction, but I got stuck along the way when the less 'reduced' expression I initially posted wasn't working as expected...Perhaps someone can point out the "logical error" from the following change of "logic" (
I'm paying careful attention to op-precedence as others have suggested that might be the problem). BTW, "?:" has higher precedence than
assignment "=". "and" is lower than both. From the orig (dropping unnecessary parens around assign before 'and' (numbering for greater easy in referring back to which step is causing problem) (0):
return ( $rh=$pkg->{'RPM_HDR'} and $dist=$rh->tag('DISTRIBUTION') )
? $pkg->{'DIST'}=$dist
: $pkg->{'DIST'}=$undef;
Logically substituting "X" for the conditional expression in parens, "( $rh=$pkg->{'RPM_HDR'} and $dist=$rh->tag('DISTRIBUTION') )", I get (1):
return X ? $pkg->{'DIST'}=$dist : $pkg->{'DIST'}=$undef;
AHAH!....I see the prob...that "=" on the "end" (before $undef)...
It is lower precedence than the ?: (as mentioned above...but wasn't sure which '=' the '?:' was interfering with). So the above (using D for "$pkg->{'DIST'}) is really (2?):
return (X ? D=$dist : D ) = $undef;
Um...
Why wouldn't that be a syntax error? the "(X?D=$dist:D)" part isn't a valid address that can be assigned to. (Note. "$undef" != undef, it's equal to a string of length 5 characters, 'undef').
I can see why what I wrote would be wrong -- but why wouldn't Perl flag it as illegal syntax?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.