Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
LanX gets eaten by a black hole popping up in the vacuum of his head
[Eily]: that a black hole formed there would rather be the sign of a head too full
LanX can't hint anymore to zentaras video because he disappeared
[LanX]: auto-subtitles in YT are entertaining: "fuehrer" instead of fewer, "jews" instead of juice ...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-06-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (552 votes). Check out past polls.