Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Looping through an array of hashrefs

by misterperl (Pilgrim)
on Sep 24, 2014 at 14:41 UTC ( [id://1101806]=note: print w/replies, xml ) Need Help??


in reply to Re: Looping through an array of hashrefs
in thread Looping through an array of hashrefs

# a simplified approach with less clutter you might find useful.. To me, reducing code I have to maintain 50% makes my job 1/2 as difficult.. You pass in an arrayref you didn't need any returned val I don't think....
sub validate_properties { for ( @{$_[0]} ) { $_->{supported} = 0; $_->{supported}++ if .5 < rand; } }

Replies are listed 'Best First'.
Re^3: Looping through an array of hashrefs
by SuicideJunkie (Vicar) on Sep 24, 2014 at 15:35 UTC

    In that case, why not eliminate half the code in that loop?:

    sub validate_properties { for ( @{$_[0]} ) { $_->{supported} = .5 < rand; } }

    Or even inline it as: $_->{supported} = .5 < rand for @array;?

    Based on the (modified) original post, it should be $_->{supported} = isSupported($_) for @properties; rather than random.
    I don't see how saving the results of an isSupported() test could be described as "validating properties", but I suppose that's a lack of context speaking.

      nice tips thanks I can use that :) Voted u a ++...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1101806]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found