Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Clean way of adding values to complex data structure

by blokhead (Monsignor)
on Jul 22, 2009 at 21:00 UTC ( #782441=note: print w/replies, xml ) Need Help??


in reply to Clean way of adding values to complex data structure

No need to nest loops. The condition you mentioned can be checked without iterating through each entire hash. You still have to iterate through the array, though.
for (@$pages) { $_->{flag} = 1 if $_->{url} eq "/html/about.html"; }
If you want to get really fancy, it can be a one liner, but I think that using logical connectives (and/or) for flow control hurts readability, especially in a complex statement with modifiers.
$_->{url} eq "/html/about.html" and $_->{flag} = 1 for @$pages;

blokhead

Replies are listed 'Best First'.
Re^2: Clean way of adding values to complex data structure
by Rodster001 (Pilgrim) on Jul 22, 2009 at 21:13 UTC
    Just what I was looking for... thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://782441]
help
Chatterbox?
[stevieb]: ahhh yes, it *is* a ref. I had forgotten that. I too have learned something. I quit too!!
[marioroy]: Is List::Util::XS a core Perl module?
[stevieb]: corelist List::Util::XS says "List::Util::XS was first released with perl v5.10.1"
[stevieb]: so yes, since v5.10.1 :)
[MidLifeXis]: According to [metaperl:// corelist], Perl 5.10.1
Lady_Aleena blurbles. One of her favorite modiles is now in "maintenance mode" in favor of a new fangled module.
[MidLifeXis]: D'oh. Slow out of the gate.
[marioroy]: Thanks stevieb, MidLifeXis.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2017-05-24 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?