Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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.

--MidLifeXis


Comment on Re: given and for
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-09-18 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls