Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 lurking in the Monastery: (5)
As of 2014-12-25 17:16 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (161 votes), past polls