in reply to faulty expression prob

I suspect you are running into a precedence issue, specifically with the conditional operator (?:) and the assignment operator (=). See perlop.

Personally, though, I found the code hard to read. I'd probably write it something like this:

$rh = $pkg->{'RPM_HDR'}; $dist = $rh->tag('DISTRIBUTION'); # or $dist = $pkg->{'RPM_HDR'}->tag('DISTRIBUTION'); $pkg->{DIST} = $dist ? $dist : $undef; # $undef or undef?

Update: Given how you are testing for truth, keep in mind what Perl considers to be a true value (vs a defined value). See True or False? A Quick Reference Guide for examples.

Replies are listed 'Best First'.
Re^2: faulty expression prob
by ikegami (Pope) on Apr 03, 2008 at 07:55 UTC
    You removed the check that prevented the method tag from being called on an undefined value.
    $dist = $rh->tag('DISTRIBUTION');
    should be
    $dist = $rh && $rh->tag('DISTRIBUTION');

    Also,

    $pkg->{DIST} = $dist ? $dist : undef
    can be written as
    $pkg->{DIST} = $dist || undef
      Um...somewhere along the line, someone dropped a "$" before "undef"..."$undef" != undef, but $undef = 'undef''; In answer to next Q, I did want assignments -- they needed to be evaluated or done left-to-right, where the 'right' side isn't done if the left side fails... If I wanted to use "==" instead of assignment, I would have preferred '&&' over 'and'. I try to use 'and' && 'or' when I don't want them interfering with an assignment.

        where the 'right' side isn't done if the left side fails...

        That's what $rv && does.

        Update: Hum, at first, I thought you you were disagreeing with what I posted, but I think you were just confirming what I said.

Re^2: faulty expression prob
by apl (Monsignor) on Apr 03, 2008 at 10:59 UTC
    Thanks for breaking out the assignments. I kept wondering if perl-diddler didn't actually want equality tests as opposed to assignments in his original code...