Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: Is there a shorter, more elegant way to write this deep hashlookup statement

Reply
Thread Tools

Re: Is there a shorter, more elegant way to write this deep hashlookup statement

 
 
C.DeRykus
Guest
Posts: n/a
 
      02-19-2013
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is there a shorter, more elegant way to write this deep hashlookup statement Dr.Ruud Perl Misc 1 02-21-2013 04:37 PM
Re: Is there a shorter, more elegant way to write this deep hash lookup statement Ted Zlatanov Perl Misc 0 02-21-2013 04:35 PM
Re: Is there a shorter, more elegant way to write this deep hash lookup statement George Mpouras Perl Misc 0 02-17-2013 12:07 PM
There's got to be a more elegant way Lilith C++ 8 09-02-2005 06:34 AM
Is there a more elegant way to do this? Kamilche Python 7 06-29-2004 04:33 AM



Advertisments