Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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?
[Discipulus]: choroba if let your company to hire Tanktalus and marioroy ... what a big fishing!
[Discipulus]: i choice prague!!
[choroba]: 1200 years is enough :-)
[marioroy]: Lady_Aleena my $ans = qx! find . -name "*.pl" -exec ls -l {} \\; !;
[Tanktalus]: My basic problem right now is that if I were willing to move, I could be back in Toronto with a pay raise. We have a number of reasons for not wanting to do that.
[marioroy]: I had to backslash the backslash inside qx.
[Tanktalus]: marioroy++ # nice catch
[Lady_Aleena]: marioroy, that makes kinda makes sense.
[Discipulus]: yes i can survive also in younger town.. but when i passed i saw many strange letters..
[Lady_Aleena]: marioroy, sorry, I am not making sense right now.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-04-23 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.