perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:
But it doesn't work. Less elegant alternatives work like:return ( ($rh=$pkg->{'RPM_HDR'}) and $dist=$rh->tag('DISTRIBUTION') ) ? $pkg->{'DIST'}=$dist : $pkg->{'DIST'}=$undef;
And the verbose, very steppable:( ($rh= $pkg->{'RPM_HDR'}) and $dist=$rh->tag('DISTRIBUTION')) and return $pkg->{'DIST'}=$dist; return $pkg->{'DIST'}=$undef;
I thought the conditional return expressed what I wanted the best, but it ends up return "$undef" when it should be returning "$dist". I.e. "$pkg->{'RPM_HDR'}" contains a pointer to an rpm_header, and $rh does have a valid tag for "DISTRIBUTION". Is there a reason why (this is in 5.8.8, BTW), why it wouldn't? As I understand the return's expression, if should 1st do the assignment to $rh (and test the result for defined & nonzero). If that is true, then it should do the 2nd part after then 'and' -- so that "should" assign the tag from $rh to $dist -- it is also defined and nonzero. So, since true, eval 1st expression and return it (the line containing 'dist'. So what am I missing -- why doesn't the more 'attractive' one work? *sigh* TIA...if ($rh=$pkg->{'RPM_HDR'}) { if ($dist=$rh->tag('DISTRIBUTION')) { $pkg->{'DIST'}=$dist; return $dist; } } return $undef;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: faulty expression prob
by BrowserUk (Patriarch) on Apr 03, 2008 at 03:34 UTC | |
|
Re: faulty expression prob
by jwkrahn (Abbot) on Apr 03, 2008 at 03:27 UTC | |
by perl-diddler (Chaplain) on Apr 03, 2008 at 23:07 UTC | |
by jwkrahn (Abbot) on Apr 04, 2008 at 02:41 UTC | |
|
Re: faulty expression prob
by bobf (Monsignor) on Apr 03, 2008 at 03:30 UTC | |
by ikegami (Patriarch) on Apr 03, 2008 at 07:55 UTC | |
by perl-diddler (Chaplain) on Apr 03, 2008 at 23:17 UTC | |
by ikegami (Patriarch) on Apr 04, 2008 at 00:32 UTC | |
by apl (Monsignor) on Apr 03, 2008 at 10:59 UTC | |
|
Re: faulty expression prob
by grizzley (Chaplain) on Apr 03, 2008 at 07:33 UTC | |
by parv (Parson) on Apr 04, 2008 at 03:45 UTC |