in reply to Re: How to eliminate warning message on hash value?
in thread How to eliminate warning message on hash value?

As a minor note, I would get rid of the nested if and replace that with an "and".

Update: fixed line wrap as per Ikegami's suggestion.
line length settings are different in my normal editor than PM. When I do complex multi-part if's requiring more than one line, I do it like below with the conditions on top of each other and the connecting "or" or "and" to the left.

if ( defined($$keyptr) ) { my $datapos = $RSubtree{$curuser}{$$keyptr}; if ( defined($datapos) #update and GetDataRecord( $db, $keyptr, $dataptr, $datapos ) ) { flock( $db->{btree}, LOCK_UN ); return ""; } }
instead of:
if ( defined($$keyptr) ) { my $datapos = $RSubtree{$curuser}{$$keyptr}; if ( defined($datapos) ) { if ( GetDataRecord( $db, $keyptr, $dataptr, $datapos ) ) { flock( $$db{btree}, LOCK_UN ); return ""; } } }

Replies are listed 'Best First'.
Re^3: How to eliminate warning message on hash value?
by ikegami (Patriarch) on Dec 20, 2011 at 00:43 UTC

    As a minor note, I would get rid of the nested if and replace that with an "and".

    Your code gets wrapped (with default PM settings), and is thus less readable. The line break was intentional, at which point "if" works better.

      I updated the post. I didn't notice the line length issue before. Lines on PM are shorter than I normally use, but this is solved easily as shown. Very complicated conditions can be made readable in this "vertical" manner.

      Update: As a historical note, I learned this method from Daniel McCraken when I was working with FORTRAN IV some years ago.

        I didn't say it couldn't be done, I said "if" worked better. (No artificial code placement, nested instead of zizag indenting.)