Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: C-style for loop

by toolic (Bishop)
on Nov 15, 2008 at 19:12 UTC ( #723829=note: print w/ replies, xml ) Need Help??


in reply to C-style for loop

Those 2 loops do quite different things.

If your goal is to create a new array, @cleaned_values, from another array, @values, you could use a "for" loop like this:

for (@values) { push @cleaned_values, _clean_cgi_param($_); }

Alternately, you could use map for this:

@cleaned_values = map { _clean_cgi_param($_) } @values;

Update: The code in the OP was modified after I composed this node.


Comment on Re: C-style for loop
Select or Download Code
Re^2: C-style for loop
by ursus (Acolyte) on Nov 17, 2008 at 18:18 UTC
    Yes! Use map()!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2015-07-05 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls