Learning Perl by Schwartz Randal L.;foy brian d;Phoenix Tom;

Learning Perl by Schwartz Randal L.;foy brian d;Phoenix Tom;

Author:Schwartz, Randal L.;foy, brian d;Phoenix, Tom;
Language: eng
Format: epub
Publisher: O'Reilly Media, Incorporated
Published: 2021-06-29T00:00:00+00:00


for (1..10) { # really a foreach loop from 1 to 10 print "I can count to $_!
"; }

That’s really a foreach loop, but it’s written for. Perl figures it out based on what it finds in the parentheses. If it finds the semicolons, it’s the C-style for. Except for this one example, throughout this book we’ll spell out foreach wherever it appears. How you do it is an issue of your personal style.

In Perl, the true foreach loop is almost always a better choice. In the foreach loop (written for) in that previous example, it’s easy to see at a glance that the loop will go from 1 to 10. But do you see what’s wrong with this computed loop that’s trying to do the same thing?



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.