Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: given and for

by MidLifeXis (Monsignor)
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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988721]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-04-19 12:48 GMT
Find Nodes?
    Voting Booth?