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

Re: given and for

by MidLifeXis (Prior)
on Aug 21, 2012 at 12:58 UTC ( #988721=note: print w/ replies, xml ) Need Help??

in reply to given and for

Why does Perl have while when we have if / goto? They can both do the same thing, right?

Just because you can shoehorn some construct into doing something else does not mean that that it is the best tool for the job. It may not be the clearest indication of the programmers intent, may cause confusion with a person later reading the code, and so on. To me, there would be a disconnect between the for / when, and every time I would read it, there would be a short time where I would have to do a mental switch between "this is a loop" and "this is a set of choices based on a value". For the given / when, I would immediately be expecting a set of choices.

There is also a false assertion in your question - that the two constructs do the same thing. See the output for perl -MO=Terse ... for the two samples given. moritz has gone into some of the differences between them in his post.


Comment on Re: given and for
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-01-31 06:16 GMT
Find Nodes?
    Voting Booth?

    My top resolution in 2015 is:

    Results (257 votes), past polls