Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Re: Is there a shorter, more elegant way to write this deep hashlookup statement (http://www.velocityreviews.com/forums/t957794-re-is-there-a-shorter-more-elegant-way-to-write-this-deep-hashlookup-statement.html)

C.DeRykus 02-19-2013 07:40 PM

Re: Is there a shorter, more elegant way to write this deep hashlookup statement
 
On Saturday, February 16, 2013 4:16:33 PM UTC-8, Ignoramus329 wrote:
> As I always say 'use strict; use warnings', I have this statement in my program:
>
>
>
> $is_freight = 1
>
> if $ebay_record
>
> && $ebay_record->{ShippingDetails}
>
> && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}
>
> && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}->{ShippingService}
>
> && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}->{ShippingService} eq 'Freight';
>
>
>
> This is a correct statement and it does not give errors or warnings,
>
> however, I would like to know if I can write it in a shorter way.
>
>
>
> Any suggestions?
>
>


I haven't used it but there's a module providing a
a pragma to lexically disable autovivifying:

http://search.cpan.org/~vpit/autoviv...ivification.pm

so, untested, you could do something like this:

no autovivification;

$is_freight = 1
if ebay_record->...->{ShippingService} eq 'Freight';


and $is_freight would remain undefined unless all levels
existed.

Needs a careful read for default behavior and
CAVEATS section.

--
Charles DeRykus


All times are GMT. The time now is 09:20 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.